노무현 대통령 배너

AS3.0에서 stage.stageWidth 와 stage.width 의 차이

by on 5.09, 2009, under AS3.0 API

stageWidth feather

AS2.0 의 Stage 에는 width 와 height 속성[01] 이 있어 스테이지의 폭과 높이를 구할 수 있었습니다.

AS3.0 의 stage[02]  에도 width 와 height 속성이 있습니다만, AS2.0와는 다른 width 와 height 속성을 표시합니다. F1 레퍼런스의 stage 클래스의 속성부분 설명에는 AS3.0의 width와 height 는 표시 객체(DisplayObject : DO)의 폭을 픽셀 단위로 나타낸다고 되어 있습니다. 즉 stage에 전체적인 면적을 커버하는 배경 이미지 같은 것이 없다면 stage 위에 있는 DisplayObject들만의 width와 height를 나타냅니다.

그 대신 AS2.0 의 Stage.width와 Stage.height 는 AS3.0에서는 각각 stage.stageWidth와 stage.stageHeight가 대신하게 되었습니다. 혹시 헷갈리는 분은 아래 swf 를 보시죠.

stageWidth_example.swf 
이 파일을 클릭해서 FlashPlayer 또는 브라우저로 창 사이즈 조절도 해보세요.

버튼을 클릭해서 깃털 객체를 하나 더 만들면 깃털 하나가 200 픽셀이므로 이미 stage 에 표시되어있는 200 픽셀과 더해서 400 픽셀이 됨을 알 수 있습니다. 새로 생성한 깃털은 드래그도 가능하므로 움직여 보세요.

 

혹시 사용된 코드가 궁금하신 분은 아래를…

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
stage.scaleMode = "noScale";
stage.addEventListener( Event.RESIZE, stageResizeHandler );
 
function stageResizeHandler( e:Event = null ):void
{
	txtWidth.text = "stage.width : " + stage.width;
	txtStageWidth.text = "stage.stageWidth : " + stage.stageWidth;
}
stageResizeHandler();
 
//new Feather() 버튼
copyButton.addEventListener( MouseEvent.CLICK, featherClickHandler );
 
function featherClickHandler( e:MouseEvent ):void
{
	var feather:Feather = new Feather();//라이브러리 패널에서 Feather 로 정의함
	addChild( feather );
	feather.buttonMode = true;
	feather.addEventListener( MouseEvent.MOUSE_DOWN, featherMouseDownHandler );
	feather.addEventListener( MouseEvent.MOUSE_UP, featherMouseUpHandler );
	stageResizeHandler();
}
 
function featherMouseDownHandler( e:MouseEvent ):void
{
	e.currentTarget.startDrag();
	stage.addEventListener( MouseEvent.MOUSE_MOVE, stageResizeHandler );
}
 
function featherMouseUpHandler( e:MouseEvent ):void
{
	e.currentTarget.stopDrag();
	stage.removeEventListener( MouseEvent.MOUSE_MOVE, stageResizeHandler );
}
이 글을 복사해서 퍼가시는건 허용하지 않습니다. 글의 주소를 다른곳에 알려주시는 것은 환영합니다.
  1. 무비클립과는 달리 _width, _height 가 아닙니다. []
  2. AS2.0은 Stage(대문자 S) 였지만 AS3.0은 소문자 입니다. []

관련된 글

:, , , , , , , , ,

6 Comments for this entry

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Meta