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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

Programming HTML and JavaScript in AIR<br />

Creating an object using the name of the class as a string parameter<br />

Adobe AIR 1.0 and later<br />

Consider a hypothetical JavaScript class defined with the following code:<br />

var CustomClass =<br />

{<br />

Utils:<br />

{<br />

Parser: function(){ alert('constructor') }<br />

},<br />

Data:<br />

{<br />

}<br />

};<br />

var constructorClassName = "CustomClass.Utils.Parser";<br />

The simplest way to create a instance would be to use eval():<br />

var myObj;<br />

eval('myObj=new ' + constructorClassName +'()')<br />

However, you could avoid the call to eval() by parsing each compon<strong>en</strong>t of the class name and building the new object<br />

using bracket notation:<br />

function getter(str)<br />

{<br />

var obj = window;<br />

var names = str.split('.');<br />

for(var i=0;i

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

Saved successfully!

Ooh no, something went wrong!