Player /
ActionScript API
How to control the Vimeo player when it’s embedded in a Flash 10 project.
Embedding Moogaloop in your Flash project
Moogaloop is the code name for our Flash player. It’s a long story, don’t ask.
You cannot embed Moogaloop in your Flash project unless you are using ActionScript 3. It will not work in ActionScript 2.
In order to include the Vimeo player in your project, we have developed a simple class, VimeoPlayer.as, that allows you to easily add video support and access all the necessary APIs you made need for your Flash project.
The main goal of this class is to provide all the basic elements to get a Vimeo player to load into your Flash project. Feel free to add any additional methods or variables to this class that suit the needs of your project.
Here's an example of how you would create a new VimeoPlayer object in your project.
var player : VimeoPlayer = new VimeoPlayer(oauth_key, clip_id, width, height, fp_version, api_version);
Parameters
| oauth_key:String | REQUIRED The Consumer Key that has been assigned to your application. If you don't have any applications registered, you can register your application now. |
| clip_id:int | REQUIRED The clip_id for the video you want to load into the player. Don't worry, you can alway load another clip into the player via the loadVideo method (see below). |
| width:int (default = 400) | The width you want the player to be in your project. |
| height:int (default = 300) | The height you want the player to be in your project. |
| api_version:int (default = 2) | The API version you want to use in your project. The available API versions are 1 or 2. We recommend that you use version 2 in order to extend the life of your integration, as version 1 is deprecated. |
API Reference
Below is a listing of the properties, methods, and events that are available via the Moogaloop API.
Properties
| bytesLoaded:Number | [read-only] Returns the number of bytes loaded for the video. NOTE: Playback needs to be initiated before this property reflects the actual data. |
| bytesTotal:Number | [read-only] Returns the total bytes of the video. NOTE: Playback needs to be initiated before this property reflects the actual data. |
| color:uint | Indicates the current color applied to the player controls. |
| currentTime:Number | [read-only] Returns the current playback time of the video. |
| duration:Number | [read-only] Returns the duration of the video. |
| size:Object | [read-only] Returns an object containing the current width and height of the player.(ex. player.size.width) |
| videoEmbedCode:String | [read-only] Returns the embed code for the current state of the player. |
| videoHeight:Number | [read-only] Reutrns the native resolution height of the video in the player. |
| videoUrl:String | [read-only] Returns the URL for the video on Vimeo. |
| videoWidth:Number | [read-only] Returns the native resolution width of the video in the player. |
| volume:Number | Indicates the current volume level set in the player. |
Methods
| destroy():void | Kills all video playback, events and objects in the player. Intended to be used before removing the player from your Flash project. |
| getColor():String | Returns the hex color of the player. |
| getCurrentTime():Number | Returns the elapsed time of the video in seconds. Accurate to 3 decimal places. |
| getDuration():Number | Returns the duration of the video in seconds. Accurate to 3 decimal places after the video's metadata has been loaded; accurate to the second before the metadata has loaded. |
| getLoop():Boolean | Returns whether or not loop is turned on. |
| getVideoEmbedCode():String | Returns the iframe embed code for the video. |
| getVideoUrl():String | Returns the Vimeo URL of the video. |
| getVolume():Number | Returns the player's current volume, a number between 0 and 1. |
| loadVideo(clip_id:int) | Loads a new video into the player based on the clip_id passed to the method. |
| pause():void | Pauses the video. |
| paused():Boolean | Returns false if the video is playing, true otherwise. |
| play():void | Plays the video. |
| seek(seconds:Number):void | Seeks to the specified point in the video. Will maintain the same playing/paused state. The Flash player will not seek past the loaded point, while the HTML player will seek to that spot regardless of how much of the video has been loaded. |
| setColor(color:String):void | Sets the hex color of the player. Accepts both short and long hex codes. |
| setLoop(loop:Boolean):void | Toggles loop on or off. |
| setSize(width:int, height:int) | Sets the width and height of the player. |
| setVolume(volume:Number):void | Sets the volume of the player. Accepts a number between 0 and 1. |
| unload():void | Reverts the player back to the initial state. |
Events
Events can be added to Moogaloop via the native Flash method for adding event listeners, addEventListener. For events that return properties, those are located within the data:Object property in the event. Below is a listing of the events and the data that they return, if any.
Please note: Since not all events return data, you should check for the existence of the data object in the event before accessing it. This will also help with any warnings/errors that Flash can throw when publishing from the Flash IDE (ie. not using the command-line compiler).
Event Example
player.addEventListener('loadProgress', loadProgressHandler, false, 0, true);
private function loadProgressHandler(event:Event) : void
{
if (event.hasOwnProperty('data') && Object(event).data) {
trace('Percent loaded: ' + Object(event).data.percent);
}
}
The following events are available to listen to:
| error |
Fired when an error occurs in the player. Data Properties
|
||||||||
| finish | Fires when the video playback reaches the end. | ||||||||
| loadProgress |
Fired as the video is loading. Data Properties
|
||||||||
| pause | Fired when the video pauses. | ||||||||
| play | Fired when the video begins to play. | ||||||||
| playProgress |
Fired as the video is playing. Data Properties
|
||||||||
| ready | Fired as soon as the player has finished requesting the clip info and is ready for playback, either on the initial load of the player or after a loadVideo request. |
||||||||
| seek |
Fired when the user seeks. Data Properties
|
Examples
We've created an example of how to use Moogaloop in your Flash projects: ActionScript example on Github.