Interacting with actionscript 3.0 using javascript

杀马特。学长 韩版系。学妹 提交于 2019-12-11 06:49:52

问题


As the title says... I'm trying to interact with my flash movie's actionscript via javascript. Specifically I'm trying to send text to my flash movie. I've come across a couple sites that had some walkthroughs but I for the life of me could not get them to work.

From the adobe site. http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_15683&sliceId=1

the really cool thing about that is their source file download link is dead. and coming across another post:

http://www.jesuscarrera.info/2009/01/05/communication-between-actionscript-3-and-javascript/

The download works... except the fla file is blank and running the html page you can receive text from the flash movie... but you can't send text from html to the flash movie.

I followed the steps pretty closely, can anybody see anything wrong w/ the instructions on the adobe site? And if ANYBODY can reeeeeally help me out, could you post a source example of this functionality? Thanks everybody for your time!


回答1:


a little more searching yielded:

http://blog.circlecube.com/2008/02/01/actionscript-javascript-communication/

:) hope this helps someone else.




回答2:


The example you posted uses the ExternalInterface class to communicate from Flash to Javascript. You can add callbacks using the ExternalInterface but if you need to trigger a function from the DOM (HTML) that goes to FLASH.

OK, now to get values from Javascript to Flash there are a few options.
You can set up a callback function using the ExternalInterface Class. Here is an example from Live Docs link text

If you need to call the Flash from Javascript without ANY Flash interaction (like to play a video or something), again you will use the ExternalInterface. Here is an AS3 example link text

Here is an AS2 example to answer your question:

//AS2
import flash.external.*;
function helloWorld():Void
{
    //Do something
}
ExternalInterface.addCallback("myFunction", helloWorld);

// HTML
<script language="JavaScript">

    flashObject.myFunction();
</ script>
...
<object id="flashObject"...>
    ...
    <embed name="flashObject".../>
</object>



回答3:


Had to do some work on this recently and found that this article helped a lot:

http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_15683



来源:https://stackoverflow.com/questions/460242/interacting-with-actionscript-3-0-using-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!