setNew

Creates a new instance of a class object.


Availability:

First available in version 3.0 build 2039.


Input Parameters:

variable - String - The full name of an ActionScript variable that will contain the reference to the new instance (e.g. "_level0.my_xml").

targetClass - String - The full name of the class object for which a new instance will be created (e.g. "XML").


Output Parameters:

value - String - The string representation of the value returned by the executed command. The value is always the current value, not necessarily the value at the time of the command execution.


Notes:

The path to the variable and targetClass must originate in _level0 or _global. If you are calling a function from _global, you must specify "global" - _global without the inital underscore. Default path for variable is _level0. Default path for targetClass is _global.


Examples:

Example 1:
In this example we create a new instance of the TextFormat object, so we can manipulate a textfield residing in our main Flash movie.

var txtFmt_obj = Flash.setNew({variable:"_level0.txtFmt",targetClass:"TextFormat"});

Example 2:
Expanded example from above. Also see Flash.execute, Flash.setVar, and Flash.setDatatype.

Flash.execute({method:"_level0.createTextField",args:["my_txt",1,0,0,1,1]});

var txtFmt_obj = Flash.setNew({variable:"_level0.txtFmt",targetClass:"TextFormat"});

Flash.setVar({variable:"_level0.txtFmt.bold",value:true});
Flash.setVar({variable:"_level0.txtFmt.font",value:"Verdana"});
Flash.setVar({variable:"_level0.txtFmt.size",value:12});
Flash.setVar({variable:"_level0.txtFmt.color",value:"0xFF0000"});

var txtFmt_eval = Flash.setDatatype({type:"eval",value:"_level0.txtFmt"});
Flash.execute({method:"_level0.my_txt.setNewTextFormat",args:[txtFmt_eval]});

Example 3:
This example creates a new XML object in the main movie. We could then use other methods to manipulate the XML object. Tracing the value property of the returned object will always reveal the current value of the variable.

var myXML_obj = Flash.setNew({variable:"_level0.my_xml",targetClass:"XML"});
trace(myXML_obj.value);