13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Cli<strong>en</strong>t system <strong>en</strong>vironm<strong>en</strong>t<br />

private static function getBrowserObjects():Array<br />

{<br />

var itemArr:Array = new Array();<br />

var itemVars:URLVariables;<br />

if (ExternalInterface.available)<br />

{<br />

try<br />

{<br />

var tempStr:String = ExternalInterface.call("JS_getBrowserObjects");<br />

itemVars = new URLVariables(tempStr);<br />

for (var i:String in itemVars)<br />

{<br />

itemArr.push({name:i, value:itemVars[i]});<br />

}<br />

}<br />

catch (error:SecurityError)<br />

{<br />

// ignore<br />

}<br />

}<br />

return itemArr;<br />

}<br />

If the external API is available in the curr<strong>en</strong>t user <strong>en</strong>vironm<strong>en</strong>t, the Flash runtime calls the JavaScript<br />

JS_getBrowserObjects() method, which loops over the browser’s navigator object and returns a string of URL<strong>en</strong>coded<br />

values to ActionScript. This string is th<strong>en</strong> converted into a URLVariables object (itemVars) and added to the<br />

itemArr array, which is returned to the calling script.<br />

Communicating with JavaScript<br />

Flash Player 9 and later<br />

The final piece in building the CapabilitiesExplorer application is writing the necessary JavaScript to loop over each of<br />

the items in the browser’s navigator object and app<strong>en</strong>d a name-value pair to a temporary array. The code for the<br />

JavaScript JS_getBrowserObjects() method in the container.html file is as follows:<br />

<br />

function JS_getBrowserObjects()<br />

{<br />

// Create an array to hold each of the browser's items.<br />

var tempArr = new Array();<br />

// Loop over each item in the browser's navigator object.<br />

for (var name in navigator)<br />

{<br />

var value = navigator[name];<br />

// If the curr<strong>en</strong>t value is a string or Boolean object, add it to the<br />

// array, otherwise ignore the item.<br />

switch (typeof(value))<br />

{<br />

case "string":<br />

case "boolean":<br />

// Create a temporary string which will be added to the array.<br />

// Make sure that we URL-<strong>en</strong>code the values using JavaScript's<br />

Last updated 6/6/2012<br />

875

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!