Yep, even better.

-TH

--- In [email protected], "ag_rcuren" <robert.vancuren...@...> wrote:
>
> Why not just use the addedToStage event instead? This will guarantee that 
> stage is not null.
> 
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
>     addedToStage="init();">
> 
>     public function init():void
>     {
>         stage.addEventListener(Event.RESIZE, resizeHandler);
>     }
> 
>     private function resizeHandler(event:ResizeEvent):void
>     {
>         trace("height:" + stage.height);
>         trace("height:" + stage.width);
>     }
> 
> --- In [email protected], "turbo_vb" <TimHoff@> wrote:
> >
> > Btw, adding a new topic every few hours that addresses the same issue, but 
> > with a slightly different name, is really bad form.
> > 
> > -TH
> > 
> > --- In [email protected], "turbo_vb" <TimHoff@> wrote:
> > >
> > > The stage isn't available immediately.  That's why you get a null error.
> > > With a little trickery:
> > > 
> > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
> > > 
> > > creationComplete="onCreationComplete()"
> > > 
> > > resize="getStageDimensions()">
> > > 
> > > 
> > > 
> > > 
> > > <mx:Script>
> > > 
> > > <![CDATA[
> > > 
> > > private function onCreationComplete():void
> > > 
> > > {
> > > 
> > > callLater( getStageDimensions );
> > > 
> > > }
> > > 
> > > 
> > > 
> > > 
> > > private function getStageDimensions():void
> > > 
> > > {
> > > 
> > > if ( stage )
> > > 
> > > {
> > > 
> > > trace( "height:" + stage.height );
> > > 
> > > trace( "width:" + stage.width );
> > > 
> > > }
> > > 
> > > }
> > > 
> > > ]]>
> > > 
> > > </mx:Script>
> > > 
> > > 
> > > 
> > > 
> > > -TH
> > > 
> > > --- In [email protected], "markflex2007" <markflex2007@>
> > > wrote:
> > > >
> > > >
> > > > I try to get current stage size with the code,but I get error
> > > > "TypeError: Error #1009: Cannot access a property or method of a null
> > > object reference.".
> > > > It seems I get error for stage.height.
> > > >
> > > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
> > > layout="absolute"
> > > >     creationPolicy="all" resize="resizeHandler(event)">
> > > > <mx:Script>
> > > >  <![CDATA[
> > > >   import mx.events.ResizeEvent;
> > > >
> > > >
> > > >   private function resizeHandler(event:ResizeEvent):void{
> > > >
> > > >
> > > >      trace("height:" + stage.height);
> > > >      trace("height:" + stage.width);
> > > >
> > > >   }
> > > >  ]]>
> > > > </mx:Script>
> > > >
> > > > ...
> > > > ...
> > > >
> > > > </mx:Application>
> > > >
> > > >
> > > > Please help me.Thanks
> > > >
> > > > Mark
> > > >
> > >
> >
>


Reply via email to