You can use the Adobe Flash's ExternalInterface API to communicate between Javascript and ActionScript. Browser Support: IE 5.0+, Firefox 1.0+, Safari 1.3+, Opera, Chrome (versions N/A but old enough).
Flash TO Javascript Communication;
In your AS3/Flash:
function sendToJS(obj:Object):void {
if (ExternalInterface.available) {
ExternalInterface.call("onFlashCall", obj);
}
}
In your HTML/Javascript:
<head>
<script type="text/javascript">
function onFlashCall(obj) {
console.log("Data received from Flash: ", obj);
}
</script>
</head>
Javascript TO Flash Communication;
In your AS3/Flash:
public function onJavascriptCall(obj:Object):String
{
console.log("Data received from Javascript: ", obj);
}
ExternalInterface.addCallback("sendToFlash", onJavascriptCall);
In your HTML/Javascript:
<head>
<script type="text/javascript">
function sendToFlash(obj) {
var flashElem = document.getElementById("flashObject");
flashElem.sendToFlash(obj);
}
</script>
</head>
<body>
<!-- Embeded Flash SWF -->
<object id="flashObject"...>
...
<embed name="flashObject".../>
</object>
</body>
Important: In Flash, not to get a security error:
In the object tag for the SWF file in the containing HTML page, set the following parameter:
<param name="allowScriptAccess" value="always" />
In the SWF file, add the following ActionScript:
flash.system.Security.allowDomain(sourceDomain);
So, in your case:
Call sendToJS() method inside your player's corresponding event handlers:
protected function onStopClick(event:MouseEvent):void
{
sendToJS("User has clicked the STOP button.");
}
protected function onPlaybackFinish(event:Event):void
{
sendToJS("Playback is complete.");
}