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;
}