is there a way to convert dynamicly?
that's the default way to convert a String:
var toVal:* = int("5");
var toVal:* = Boolean("true");
but I wan't to do this:
var type:String = "int";
var toVal:* = type("5"); // <<<<< how can I do this
Try one of:
var type:Class = int;
// or
var type:Class = flash.utils.getDefinitionByName("int") as Class;
var toVal:* = type("5");
Example program:
var test:* = "5";
var type:Class = flash.utils.getDefinitionByName("int") as Class;
var toVal:* = type("5");
if(test is String) {
trace("Test is a string"); // traces
}
if(test is int) {
trace("Test is an int"); // ignored
}
if(toVal is String) {
trace("toVal is a string"); // ignored
}
if(toVal is int) {
trace("toVal is an int"); // traces
}
Class to assign it to a strongly typed variable like that. var type:Class = Class(int), but other than that it should work.