[flexcoders] Re: how to use stage in mxml
I try this ?xml version=1.0 encoding=utf-8? mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; layout=absolute creationPolicy=all creationComplete=init() mx:Script ![CDATA[ import mx.events.ResizeEvent; private function init():void{ stage.scaleMode = StageScaleMode.NO_SCALE; } ]] /mx:Script ... ... /mx:Application I also get error: TypeError: Error #1009: Cannot access a property or method of a null object reference. Thanks for help Mark
[flexcoders] Re: how to use stage in mxml
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 flexcoders@yahoogroups.com, markflex2007 markflex2...@... 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
[flexcoders] Re: how to use stage in mxml
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 flexcoders@yahoogroups.com, turbo_vb timh...@... 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 flexcoders@yahoogroups.com, 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
[flexcoders] Re: how to use stage in mxml
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 flexcoders@yahoogroups.com, turbo_vb timh...@... 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 flexcoders@yahoogroups.com, 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 flexcoders@yahoogroups.com, 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
[flexcoders] Re: how to use stage in mxml
Yep, even better. -TH --- In flexcoders@yahoogroups.com, 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 flexcoders@yahoogroups.com, 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 flexcoders@yahoogroups.com, 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 flexcoders@yahoogroups.com, 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