0

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

  }

...

?

2 Answers 2

2

You can use

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

...

  function getReference(_varName:String):void
  {

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

...

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.