setDatatype

Prepares a value so that it will be properly evaluated in ActionScript.


Availability:

First available in version 3.0 build 2039.


Input Parameters:

type - String - Can be either "eval" or "function". The type "function" will be executed with no parameters.

value - String - The value of what you want to pass to the JScript Flash method.


Output Parameters:

None.


Notes:

If value is a path to a variable in the main movie, the path to the method must originate in _level0 or _global, or be one of the intrinsic functions of the Flash Player. If you are calling a function from _global, you must specify "global" - _global without the inital underscore. Default path is _level0.


Examples:

Example 1:
In this example we encapsulate the value "_level0.txtFmt". We choose the type "eval" so that the value will be evaluated in ActionScript, rather than taking the literal value as a string - we want to act on the actual variable contents, not the name of the variable.

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

Example 2:
Expanded example from above. This shows how to create a textfield, create a new instance of TextFormat, set its properties, and then set the new TextFormat object for the textfield. We use Flash.setDatatype here so that the setNewTextFormat method is passed the TextFormat object we created, not just the name of the variable. Also see Flash.execute, Flash.setVar, and Flash.setNew.

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