이 값은 ActionScript 3.0 프로젝트를 진행할 시에 정해진 Stage의 기본 폭과 높이를 알려주게 된다. 아래 블로그 글을 통해서 이 속성이 어떤 의미를 가지는지 쉽게 파악할 수 있을 것이다.
AS3.0에서 stage.stageWidth 와 stage.width 의 차이
아래 코드처럼 작성한다면 이 값들을 쉽게 참고가 가능하다. SWF 메타데이터로 100,100으로 지정했기 때문에 모든 경우가 100,100으로 나와야 하는 것이 정상이다.
package { import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; import flash.text.TextField; [SWF(width="100",height="100")] public class MainApp extends Sprite { public function MainApp() { addEventListener(Event.ADDED_TO_STAGE, onAddedToStage); } private function onAddedToStage($e:Event):void { var textField:TextField; textField = new TextField(); textField.text = stage.stageWidth + "," + stage.stageHeight; addChild( textField ); stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; textField = new TextField(); textField.text = stage.stageWidth + "," + stage.stageHeight; textField.y = 30; addChild( textField ); } } }
Flash Player 에서 직접 실행시키면 모두 100으로 나온다. 하지만 IE8에서는 처음에는 100이지만 다음에는 0이 나왔다. IE외에 다른 브라우져는 정상적으로 100이 나온다. 재미있는 것은 IE8에서 stage.scaleMode를 지정하면서 이 값이 리셋되어 버린다는 것이다. 이게 Mac의 FF3.0에서도 이런 현상이 있다고 한다.
내가 만든 Flash 애플리케이션이 모든 운영체제(Cross OS)의 모든 브라우져(Cross Browser)에서 동작하도록 하기 위해서 다음과 같은 처리가 필요하게 되었다.
package { import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; import flash.text.TextField; [SWF(width="100",height="100")] public class MainApp extends Sprite { public function MainApp() { addEventListener(Event.ADDED_TO_STAGE, onAddedToStage); } private function onAddedToStage($e:Event):void { $e.target.removeEventListener( $e.type, arguments.callee ); stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; var count:int = 0; if( stage.stageWidth === 0 && stage.stageHeight === 0 ) { stage.addEventListener( Event.ENTER_FRAME, function ($e:Event):void { if( stage.stageWidth > 0 || stage.stageHeight > 0 ) { stage.removeEventListener( $e.type, arguments.callee ); _init(); } trace( ++count ); //IE8에서 두번 들어왔다. }); } else { _init(); } } protected function _init():void { var textField:TextField; textField = new TextField(); textField.text = stage.stageWidth + "," + stage.stageHeight; addChild( textField ); } } }
Flex의 경우라면 아마도 이런 처리가 다 되어 있기 때문에 신경쓰지 않고 개발하면 될 것이다. 하지만 ActionScript 3.0으로 개발할 때에는 이런 문제를 간과하면 안될 것 같다.
참고글
Firefox 3 Mac Flash Bug stageWidth and stageHeight are 0
stageWidth is zero in IE
flash.display.Stage 클래스
flash.display.DisplayObject 클래스
글쓴이 : 지돌스타(http://blog.jidolstar.com/656)
'비공개 > Adobe Flex, ActionScript 3.0' 카테고리의 다른 글
[Flash/ActionScript]스타플 타임라인을 제작하며 도움이 되었던 개념들 (34) | 2010.03.09 |
---|---|
애플(Apple)의 마이크로소프트(Microsoft)화? (18) | 2010.02.16 |
[Flash/ActionScript]Wonderfl의 멋진 공개 플래시 코드 (8) | 2010.01.07 |
IExternalizable 인터페이스를 이용한 AMF 커스텀 직렬화 활용 (4) | 2010.01.05 |
Papervison3D와 Away3DLite를 위한 GeodesicSphere (5) | 2010.01.04 |