I'm using Flash to play an .flv movieclip on my site, but I want to have the .swf send trigger an event in my javascript when it start loading, starts playing and ends playing.
What is the best way to do that in Flash CS3 using Actionscript 3.0 ?
I'm using Flash to play an .flv movieclip on my site, but I want to have the .swf send trigger an event in my javascript when it start loading, starts playing and ends playing.
What is the best way to do that in Flash CS3 using Actionscript 3.0 ?
Share Improve this question asked Sep 1, 2008 at 20:44 Christian HollbaumChristian Hollbaum 2357 silver badges11 bronze badges3 Answers
Reset to default 5You need to use the "allowScriptAccess" flash variable in the HTML. You probably want to use "sameDomain" as the type. Note that if you go cross-domain, you also need to host a special file on the server called 'crossdomain.xml' which enables such scripting (the flash player will check for this. More info at http://kb.adobe./selfservice/viewContent.do?externalId=tn_14213&sliceId=2
The call is the easy part. :-) In the Flash code, you'll use the ExternalInterface to do the call, as documented here:
http://livedocs.adobe./flash/9.0/main/wwhelp/wwhimpl/mon/html/wwhelp.htm?context=LiveDocs_Parts&file=00001655.html
Short version: you say
ExternalInterface.call("javascriptFunction", "argument")
A mon way to do this is with the ExternalInterface class, which you can use to call JavaScript methods.
First define your JavaScript methods, for example:
<script language="JavaScript">
function startsPlaying()
{
// do something when the FLV starts playing
}
</script>
Then modify your ActionScript to call the JavaScript method at the appropriate time:
// inform JavaScript that the FLV has started playing
ExternalInterface.call("startsPlaying");
For more information, see the related Flash CS3 documentation.
if you don't want to load
import flash.external.*;
so you can also do a
getUrl("javascript:startsPlaying();");