Hi,

You could add a listener to that sprite from the inside or outside. Don't
know about the timing if it might already have passed from the out side.

The reason the stage object cannot be defined in the constructor is the
parent stage has not added it yet. :) That is where you get the event and
the stage is saying ok constructed object, your my child now, I will let you
know you have been added. Up until this point, the Sprite may have been
constructed but it still doesn't know about the stage which will eventually
be it's parent.

Peace, Mike

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

  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