Search code examples
flashactionscript-3

Is it possible to turn a string into a reference to an object?


I'm wondering, and hoping, if I can access and use a specific instance of an object if I only have the name of the object instance in a string? The code below perhaps explains it a littler better.

public function myFunction(){
    var myArbItem:mcArbItem = new mcArbItem();
    //mcSomeItem has another movieclip on it called 'itemLogo'

    //elsewhere there is an object called ArbItem
    ArbItem.addEventListener(MouseEvent.CLICK, showItem)
}

private function showItem(e:MouseEvent){
    var objectName:String = 'my' + e.target.name;
    //now I have the name of the object, that is myArbItem, can I with this
    //information e.g. set "myArbItem.itemLogo.visible = false;" 
    //or "addChild(myArbItem);"?
}

Solution

  • Use the getChildByName function.