This post consists of: http://xinpure.com/call-the-javascript-method-in-flash-actionscript-2-0/
Invoking the Javascript method in Flash ActionScript 2.0
Recently, at work, there was a need to invoke the Javascript method on a Web page from Flash ActionScript 2.0
This is a question about the interaction between Flash and Javascript.
Calling the external JavaScript method in ActionScript 2.0, using the Externalinterface.call () method
To start the test:
Mouse click Element event, Trigger Javascript method
Add the following code to the Flash element:
on(release) { ExternalInterface.call("testFlashClick");}
Add the following Javascript code in Html:
function testFlashClick() { alert(‘testToFlashClick‘);}
In theory, when a mouse clicks on a component on a Flash, it triggers the Javascript Alert pop-up window
It feels like it's doable ...
But strangely enough, there is no response at all!
Correcting errors
Error reason Externalinterface.call () Undefined
When using this method, you need to first introduce its class libraryflash.external package
Of course, you can also use the flash.external.ExternalInterface.call() call methods
Correct example
Add the following code to the Flash element:
on(release) { flash.external.ExternalInterface.call("testFlashClick");}
So the problem is solved.
Other methods
Calling an external URL in ActionScript 2.0 can use the GetURL () method
Therefore, we can also use the following code to achieve the desired effect:
on(release) { getURL("javascript: testFlashClick()");}
In other words, this is like the href attribute of the A tag in Html:<a href="javascript: testFlashClick()"></a>
The truth is the same, the effect will certainly be the same.
Calling Javascript methods in Flash ActionScript 2.0