06-24-2012 05:09 PM
I want to use stage.stageWidth and stage.stageHeight in a subclass, but I get the error message "Error #1009: Cannot access a property or method of a null object reference."
How can I solve this?
06-24-2012 07:20 PM - edited 06-25-2012 07:35 AM
You cannot access the stage until the component has been added to the display stack with addChild(). When that happens, the component receives an addedToStage event, and you can start using the stage property. Bear in mind that elegant code does not rely on such things. You may later decide to add your component into a different container, with different dimensions. Creating such a dependancy to stage is often considered bad form.
06-25-2012 01:26 AM
Once components are added to your screen , than you can use stage variable.
To do soo , in initialize method add a listener Event.ADDED_TO_STAGE , on its listener you can access stage variable.
I hope this can help you.