Flex Tutorial #007 How to get JS to call methods in SWF

Source: Internet
Author: User

In HTML, how does JS invoke the code that is already encapsulated in the SWF?

There are some things flex can not achieve, need to call JS to achieve.

Eg: when the browser form closes, a dialog box pops up prompting the user to exit? Or do you want to save the current operation?

Let JS be able to call the SWF inside the method, need to flex add a callback function

// Registering external functions Externalinterface.addcallback ("Checkexit", checkexit);

Hint: 1, the first parameter: the method of the key, in the JS call when the name is used. a second parameter: callback method name in Flex.

2, the method is best placed in the page loading completed event processing inside. (This callback function is added when the page is loaded)

Example of the invocation method of JS

<script type="Text/javascript"Language="JavaScript">functionClos () {vardata = MapContext.map.checkExit ();//Mapcontext.map this side with the ID of Object in HTML    //alert (data);    varJSON =$.parsejson (data); varURL =""; if(Confirm ("You haven't saved the control information yet, have you saved and then exited?" ") {$.ajax ({url:url, cache:false, Data:json, async:false, Success:function(Result) {if(Result) {alert ("saved successfully"); return ;    }            }        }); }Else{Event.returnvalue="Not saved, are you sure you want to leave the current page?" "; }}</Script>

Note: when calling, remember to use the ID of object, eg: swfdemo. Method name

Flex Tutorial #007 How to get JS to call methods in SWF

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.