AS3- Is it possible to call a variable from a string?

Is there a way to get getDefinitionByName () to work with any type of object, I just got it to work with the class:

 var test:Class = getDefinitionByName("myClass") as Class;

I need something like:

var myNumber:Number = 10; 
var test:Number = getDefinitionByName("myNumber") as Number;

trace(test); //10

Or is there any other way to achieve this?

+3
source share
2 answers

You must define your key codes as public Static constants in your KeyCodes class:

class KeyCodes { 
    public static const A:int = 65;
} 

Then you can use them as arguments for your function useKeyCodes:

useKeyCodes(KeyCodes.A);

This way you do not need to remember every key code.

+3
source

No.

, getDefinitionByName . [], trace(this["myNumber"]);. , , , .

, , , , .

+1

Source: https://habr.com/ru/post/1709096/


All Articles