1. In Flex, ActionScript calls JavaScript is relatively simple, and plainly is, in HTML, how to invoke JavaScript, in ActionScript on how to call on the
2. If you use JS to call as, a little trouble, in fact, is relatively simple
Mxml Code:
<?xml version= "1.0" encoding= "Utf-8"?> <mx:application xmlns:mx= "Http://www.adobe.com//mxml"
Vertical "horizontalalign=" left "backgroundcolor=" white "
initialize=" init () ">
<mx:label text=" city Name: "/> <mx:list id=" citylist "width=" "height=" "dataprovider=
" {cities} "/>
<mx:arraycollection "Cities" >
<mx:String> Beijing </mx:String>
<mx:String> Shanghai </mx:String>
</mx: arraycollection>
<mx:Script>
<![ cdata[
Private Function init (): void
{
//register callback function for JavaScript call
Externalinterface.addcallback (" Callactionscript ", ASFUNCTIONBYJS);
}
Private Function Asfunctionbyjs (city:string): void
{
cities.additem (city);
}
]] >
</mx:Script>
</mx:Application>
HTML code, which is automatically generated by Flex Builder, is used to embed flash in a Web page without looking at the code, noticing the yellow background section, which is the key part, I'm adding to it
<!--saved from Url= (0014) about:internet-->
Summary, JS Call as, probably divided into 3 steps:
1.as Register callback function with Externalinterface.addcallback
2. In the JS function according to the Flash in the Web page ID get the instance
3. Use the above to get to flash instance, call as function
The above is a small set of JavaScript to introduce you to invoke ActionScript simple method, hope to help everyone, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!