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