Search code examples
actionscript-3flashmovieclipstage

As3/Flash: how to get object from the designer stage


I am having problems getting items that i placed in my designer. I work with external classes i link to my objects i place in my designer on the timeline. I always assumed they where placed in the "stage" attribute in the as3 class.

However when i do:

trace(stage.getChildByName("thing"));

the item that i called thing in my designer is not found. It actually returns null.

Does anyone know what attribute i need to target to get the items i already placed on my stage. It would make everything a lot easier then dynamicly adding all the items.


Solution

  • If memory serves, the objects place on the stage in the editor are a child of root, not stage.

    If your code is on the timeline or the document class, the following should work.

    this.getChildByName("thing");
    

    If you are trying to access it from another object, the following should work.

    (root as DisplayObjectContainer).getChildByName("thing");