Unable to invoke javascript from flash AS2

≯℡__Kan透↙ 提交于 2019-12-11 08:42:44

问题


First of all, I'm a complete noob in Flash and don't really know what I'm doing :/ (it's a favour for a friend).

I'm working with CS6 and using action script 2.

So I've seen many people suggesting using

getURL("javascript:myFunction();");

or

import flash.external.ExternalInterface;

ExternalInterface.call("myFunction()");

for calling the method myFunction that I have in my html file (in the head). However, for some reason the method is not invoked. Apart of that I have in my frame code that just stops a flash film that ends (I tried putting this before and after the js invocation)

stop();

I do also have on my html under the <object>:

<param name="allowScriptAccess" value="always" />

and again in the nested <!--[if !IE]>--> .

(If needs be, I can add the html file as well.) Can anyone shed a light on what am I doing wrong? Removing the stop(); doesn't seem to change anything either (apart of the film being replayed.


回答1:


Ok, so the issue is a rather silly thing, but I've decided to put it down in writing in case someone in the future will stumble upon the same weird behaviour. What happened was I have installed Flash CS6 on the same day and didn't reboot my machine. After rebooting it, calling getURL("javascript:myFunction();"); simply worked- just remember to also have the <param name="allowScriptAccess" value="always" /> on your html.




回答2:


I've never used the first method, but have for the second. Try it without the brackets:

ExternalInterface.call("myFunction");



回答3:


flash.external.ExternalInterface.call("function (without brackets)","Value or Variable(Without quotes)");


来源:https://stackoverflow.com/questions/13634716/unable-to-invoke-javascript-from-flash-as2

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