Flash/flex Study Notes (9): mutual calls between actionscript3.0 and JavaScript

Source: Internet
Author: User

The principle is almost the same as that in Silverlight (see how Silverlight and JS call each other ):

Actionscript3Code:

Btncalljs. addeventlistener (mouseevent. click, fncalljs); function fncalljs (E: mouseevent): void {trace ("ready to call... "); // call the jshello method in JS and display the returned value to lblresult in the label. TEXT = externalinterface. call ("jshello", "as3 passed parameters");} function calledbyjs (P: string): String {return "calledbyjs in Flash is called, this is the parameter passed in JS: "+ P;} externalinterface. addcallback ("myfunction", calledbyjs); // here: myfunction is the name of the method exposed to JS calls.

 

Embedded in Flash pages:

<Object classid = "CLSID: d27cdb6e-ae6d-11cf-96b8-444553540000 "... id = "js_as3">... </Object> <SCRIPT type = "text/JavaScript"> function jshello (MSG) {var r = "this is the method in JS. Parameter:" + MSG; alert (R ); return R;} function fncallas (MSG) {var flashobj = document. getelementbyid ("js_as3"); var sasreturn = flashobj. myfunction ("parameters in JS"); alert (sasreturn);} fncallas ("test"); </SCRIPT>

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.