Invoking the Javascript method in Flash ActionScript 2.0

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.