问题
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