Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
Posts: 158
Registered: ‎01-11-2010
My Device: 9700 | 9900 | PlayBook | Dev Alpha
My Carrier: Many :)
Accepted Solution

question about the scope of stage object

Hello, all.  I am currently working with containers and i have a question about the stage object.

 

I have 2 files in my program

 

1) app.as

2) stuff.as

 

 

stuff.as is a common UI library i am building.  In it, i am trying to do the folowing:

 

 

stuff(){

makeUI();

}

makeUI(){


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!

 

 

 

 

 

- - - - - - - - - -
Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: question about the scope of stage object

[ Edited ]

hey dtater,

 

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:

 

 

this.addEventListener(Event.ADDED, onAdded);

 

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)
{
makeUI();

}


}

 

 

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:

 

http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/events/Event.html#ADDED

 

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.

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Developer
Posts: 158
Registered: ‎01-11-2010
My Device: 9700 | 9900 | PlayBook | Dev Alpha
My Carrier: Many :)

Re: question about the scope of stage object

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!

 

- - - - - - - - - -
Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: question about the scope of stage object

ahh man thanks! its great to be here and im just glad i can lend a helping hand like the rest of you guys! Smiley Happy

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Contributor
Posts: 23
Registered: ‎01-19-2011
My Device: Not Specified

Re: question about the scope of stage object

Going off on a tangent, I ran my app in debug mode with a break point on the code:

 

main.setSize(stage.stageWidth,stage.stageHeight);

 

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.

 

 

Highlighted
Developer
Posts: 158
Registered: ‎01-11-2010
My Device: 9700 | 9900 | PlayBook | Dev Alpha
My Carrier: Many :)

Re: question about the scope of stage object

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.

- - - - - - - - - -
Developer
Posts: 274
Registered: ‎11-01-2010
My Device: PlayBook?
My Carrier: WiFi

Re: question about the scope of stage object

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=1952513#post1952513

 

Though I always use Event.ADDED myself.

Developer
Posts: 158
Registered: ‎01-11-2010
My Device: 9700 | 9900 | PlayBook | Dev Alpha
My Carrier: Many :)

Re: question about the scope of stage object

sorry for the long delay (life as a full time student is VERY busy)

 

the solution posted has worked.  it has been marked as ther solution.

- - - - - - - - - -