A simple way for Javascript to invoke ActionScript _javascript tips

Source: Internet
Author: User

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!

Related Article

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.