最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How can I make flash cs3, actionscript send events to javascript? - Stack Overflow

programmeradmin0浏览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 ?

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 badges
Add a ment  | 

3 Answers 3

Reset to default 5

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./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();");
发布评论

评论列表(0)

  1. 暂无评论