mate64
mate64

Reputation: 10072

as3: reference to array by string (name of var)?

is it possible to create a new reference to an array by using it's varname ?

e.g.

private var _myArray:Array = new Array("a","m","d");

...

  function getReference(_varName:String):void
  {

    trace(_varName)//_myArray

    //ok, let's try to create the reference:
    var _reference:Array = Class(getDefinitionByName(_varName)) as Array;

    trace(_myArray.length)//3
    trace(_reference.length)//0

  }

...

?

Upvotes: 0

Views: 1412

Answers (2)

YeJiabin
YeJiabin

Reputation: 1038

It's possible. I think the name of definition is not correct, you may use the full definition of the class like 'flash.display.xxx' or the class you defined. This is the reference http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/utils/package.html#getDefinitionByName%28%29

Upvotes: 0

Miha
Miha

Reputation: 301

You can use

private var _myArray:Array = new Array("A","B","C");

...

  function getReference(_varName:String):void
  {

    trace(this[_varName].length)//3    
  }

...

Upvotes: 2

Related Questions