[[PlayerToc(flash)]]
= JW Player: API Calls =
The 4.0 version of the player for Flash supports an extremely flexible API, both externally (for [http://en.wikipedia.org/wiki/JavaScript javascript]) and internally (for [wiki:PluginsBuilding plugins], that can be built in [http://en.wikipedia.org/wiki/ActionScript actionscript]). It is possible to read the config/playlist variables of the player, send events to the player and assign functions as listeners. Plugins can also access specific calls/variables of one another. A small initialization routine is needed to connect your apps to the player.
== Initialization ==
=== Javascript ===
Please note that the player will NOT be available the instant your HML page is loaded and the first javascript is executed. The SWF file (40k) has to be loaded and instantiated first! You can catch this issue by defining a simple global javascript function. It is called playerReady(obj) and every player that's succesfully instantiated will call it. The 'obj' object will contain the ''id'', ''version'' and ''client'' of the player, so you immediately know what player it is an where to subscribe to. Use the ''id'' variable to get a reference to the player itself. Example:
{{{
var player;
function playerReady(obj) {
alert('the videoplayer '+obj['id']+' has been instantiated');
player = document.getElementById(obj['id']);
};
}}}
If you are not interested in calling the player when the page is loading, you won't need this function. You can then simply use the ID of the embed/object tag that embeds the player to get a reference. A simple getElementById() function will do the trick, so it can be called. This function needs the ID of the object/embed tag as a reference. So for example with this embed tag:
{{{
}}}
You can get a pointer to the player with this line of code:
{{{
var player = document.getElementById('myplayer');
}}}
'''Note you must add both the id and name attributes in the