Not in the constructor. During the constructor of a Sprite it has not yet
been added. What you need to do in your constructor is:

this.addEventListener(Event.ADDED_TO_STAGE, handleAddedToStage);

And then in handleAddedToStage() method of your class this.stage will be
valid. If you need to know when you're removed from the stage (which, AFAIK,
won't happen to your root class in an AS3 project, but will happen to other
classes, potentially) is to listen for REMOVED_FROM_STAGE.

If you wanna know when this.parent is valid, listen for Event.ADDED.

Troy.


On 5/31/07, Alex Harui <[EMAIL PROTECTED]> wrote:

   Sorry, didn't read the whole thing.



The stage should be there for the root class right away.



-Alex


 ------------------------------

*From:* [email protected] [mailto:[EMAIL PROTECTED] *On
Behalf Of *Michael Schmalle
*Sent:* Thursday, May 31, 2007 4:17 PM
*To:* [email protected]
*Subject:* Re: [flexcoders] Re: Accessing the illusive stage Object
through sprite (a near impossible feat)



Alex,

I think he said he was using an AS3 project. There is no
applicationComplete event right?

Peace, Mike

On 5/31/07, *Alex Harui* < [EMAIL PROTECTED]> wrote:

applciationComplete



systemManager.stage should be available to you at initialize


 ------------------------------

*From:* [email protected] [mailto: [EMAIL PROTECTED] *On
Behalf Of *patricklemiuex
*Sent:* Thursday, May 31, 2007 2:15 PM
*To:* [email protected]
*Subject:* [flexcoders] Re: Accessing the illusive stage Object through
sprite (a near impossible feat)



Michael,

Thanks so much, where was that event hiding? I was using a hackish
timer to do the job. However, your solution doesn't work from within
the class that I create (haven't tried outside yet). Is there a way
to do this all from inside the class I am using, or does the event
listener have to sit outside the class?

Really, I think it would have been better, but maybe it's not even
possible to make the constructor function of classes automatically
have access to the stage object on instantiation?

Also, to trap keyboard events the only way I could make it works is
the following:

stage.focus = this.parent;
this.stage.addEventListener(KeyboardEvent.KEY_DOWN,keyHandler);
this.stage.addEventListener(KeyboardEvent.KEY_UP,keyHandler);

--- In [email protected] <flexcoders%40yahoogroups.com>, "Michael
Schmalle"
<[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> The stage object does not get defined until right at the end of the
players
> init cycle.
>
> Try listening to the Sprites Event.ADDED_TO_STAGE event, then access the
> stage object.
>
> Peace, Mike
>
> On 5/31/07, patricklemiuex <[EMAIL PROTECTED]> wrote:
> >
> > Dear Actionscript wizards:
> >
> > I have an all as3.0 project.
> >
> > I can never seem to access the stage object (I've posted several times
> > and never can get any appropriate solutions)? i thought this was
> > automatic with every class that extends sprite... I get a null object
> > reference trying to access the stage object. I must be doing
> > something incorrectly, though I have studied this in a few places.
> >
> > public class AbstractSlideView extends Sprite
> > {
> > protected var _data:PictureProviderXML;
> > //protected var _data:PictureProvider;
> > private var _paramObj:Object;
> >
> > public function AbstractSlideView() {
> > var timer:Timer = new Timer(1000,1);
> > timer.addEventListener(TimerEvent.TIMER, installVars);
> > timer.start();
> > this.stage.focus = this;
> > this.addEventListener(KeyboardEvent.KEY_DOWN,keyHandler);
> > this.addEventListener(KeyboardEvent.KEY_UP,keyHandler);
> > }
> >
> >
> >
>
>
>
> --
> Teoti Graphix
> http://www.teotigraphix.com
>
> Blog - Flex2Components
> http://www.flex2components.com
>
> You can find more by solving the problem then by 'asking the question'.
>




--
Teoti Graphix
http://www.teotigraphix.com

Blog - Flex2Components
http://www.flex2components.com

You can find more by solving the problem then by 'asking the question'.

Reply via email to