Received JavaScript function return value in ActionScript 3

Source: Internet
Author: User
Mxml: <? XML version = "1.0" encoding = "UTF-8"?>

<Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml" xmlns = "*"
Creationcomplete = "oncreationcomplete ()">

<Mx: script source = "externalinterfaceasjsreturn. As"/>

<Mx: Panel Height = "300" width = "500" Title = "externalinterface: returning a value to ActionScript from JavaScript">
<Mx: canvas Height = "100%" width = "100%">
<Mx: button y = "6" label = "Get browser Info" id = "submitbutton" width = "118" x = "180">
</MX: button>
<Mx: textarea x = "5" Y = "34" width = "468" Height = "228" id = "Tarea"/>
</MX: canvas>
</MX: Panel>
</MX: Application>

 
Externalinterfaceasjsreturn.:
Import flash. External. externalinterface;
Import flash. Events. mouseevent;


Private function oncreationcomplete (): void
...{
Submitbutton. addeventlistener ("click", onsubmitclick );
}

Private function onsubmitclick (Event: mouseevent): void
...{
If (externalinterface. available)
...{
// Call the JavaScript function, and store the return value
// In a variable
VaR info: Object = externalinterface. Call ("getbrowserinfo ");

VaR SB: String = NULL;

// Loop through the results
For (var x: String in info)
...{
SB = Sb + x + ":" + info [x] + "";
}

// Print them out to the textarea
Tarea. Text = sb. tostring ();
}
}

Javascript: function getbrowserinfo ()
...{
VaR docelement = document.doc umentelement;

VaR o = new object ();

O. href = location. href;
O. lang = docelement. Lang;
O. offsettop = docelement. offsettop;
O. offsetleft = docelement. offsetleft;
O. offsetwidth = docelement. offsetwidth;
O. offsetheight = docelement. offsetheight;
O. scrolltop = docelement. scrolltop;
O. scrollleft = docelement. scrollleft;
O. scrollheight = docelement. scrollheight;
O. scrollwidth = docelement. scrollwidth;
O. clientheight = docelement. clientheight;
O. clientwidth = docelement. clientwidth;
O. width = Document. width;
O. Height = Document. height;
O. Domain = Document. domain;
O. lastmodified = Document. lastmodified;

Return O;
}

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.