views:

1572

answers:

3

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 ?

+3  A: 

A common 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.

David Crow
+4  A: 

You 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.com/selfservice/viewContent.do?externalId=tn_14213&amp;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.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&amp;file=00001655.html

Short version: you say

ExternalInterface.call("javascriptFunction", "argument")

Greg
+1  A: 

if you don't want to load

import flash.external.*;

so you can also do a

getUrl("javascript:startsPlaying();");
Jon Romero