02-01-2011 02:45 AM
Hello, all. I am currently working with containers and i have a question about the stage object.
I have 2 files in my program
stuff.as is a common UI library i am building. In it, i am trying to do the folowing:
myContainer.setSize(stage.Stagewidth , stage.Stagehight);
Flash keeps crashing at runtime saying that there is an invalid reference to a null object.
if main.as is the application file, how can i get the stage object to be valid / accessable inside my stuff.as file?
- Thanks for your time!
Solved! Go to Solution.
02-01-2011 02:52 AM - edited 02-01-2011 02:53 AM
i ran into the same problem too in the past. the only way to have access to the Stage is to have what ever class you are working added to the stage by a parent object that is already on stage. so if an object hasnt been added to the stage yet, it's stage value will be null.
the best way to work with this set back is to have an event listener set in your stuff.as file listening for the Event.ADDED event in your constructer stuff() like this:
and then in your onAdded event handler function:
private function onAdded(e:Event):void
// this event gets triggered by other objects, so we check to make sure it the right object
if (e.target == e.currentTarget)
this way the makeUI funciton will only be called when it has access to the stage.
here is more detail on the Event.ADDED event:
hope that helps. good luck!
Edit: I also forgot to add the Event.ADDED event will be called when you do the addChild(stuff); in your main application.
02-01-2011 03:21 AM
I am very tired, so i will have to impliment / test this tomorrow.
i will post back with results (and i found a few more bugs / questions in my program)
I've been a member of *many* development communities in teh past, but you Jrab are amazing. Quickest replies ever... and always helpful!
02-01-2011 03:25 AM
ahh man thanks! its great to be here and im just glad i can lend a helping hand like the rest of you guys!
02-01-2011 06:32 AM
Going off on a tangent, I ran my app in debug mode with a break point on the code:
When the breakpoint was triggered, I looked at the variables, expanded stage and scrolled down to see what the value of stage.width was, but each time it was about to show the variable and value the variables window whent white and the app crashed.
Suppose this is a bug in Burrito.
02-01-2011 11:04 AM
I was having all sorts of problems getting burito to work properly, so i moved back to FB 4.
There is a thread on adobe's site where you should post this, i think.
02-01-2011 11:59 AM
Here's a nice little read on the stage and a way of referencing the stage without Event.ADDED: http://www.kirupa.com/forum/showthread.php?p=19525
Though I always use Event.ADDED myself.