In AS3, There are times that you can not use root or parent properties on a display object. It is because root and parent properties are set to null, unless they are not added to the stage. So, an error occurs when you try to use root or parent properties in the constructor of an class. To avoid this problem, use addedToStage event object, and run codes after a display object was added to the display list.
AS3의 디스플레이 오브젝트에서 root 또는 parent 속성을 참조하지 못하는 경우가 종종 있습니다. 이는 root 및 parent 속성은 디스플레이 오브젝트가 스테이지에 애드되지 않으면 null 값을 가지기 때문입니다. 그러므로 클래스 컨스트럭터에서 root 또는 parent를 참조하려 할 때 에러가 발생하는 것입니다. 이를 해결하기 위해서 addedToStage 이벤트 오브젝트를 사용하여, 디스플레이 오브젝트가 디스플레이 리스트에 추가되었을 때 필요한 코드를 실행하도록 하면 됩니다.
AS3で、ディスプレーオブジェクトがrootやparentプロパ ティを参照できない時があります。それは、ディスプレーオブジェクトがステ―ジに追加されていないと、rootとparentプロパ ティはnullに設定されると言うわけです。だから、クラスのコンストラクタの中でrootやparentプロパ ティ参照しようとする時、エラーが発生するのです。このエラーを回避するために、addedToStageイベントオブジェクトを使用し、ディスプレーオブジェクトがディスプレーリストに追加された時、コードを実行します。

root property
root:DisplayObject [read-only]

…… The root property is set to null for any display object that has not been added to the display list, unless it has been added to a display object container that is off the display list but that is a child of the top-most display object in a loaded SWF file.

quote from ActionScript 3.0 Language and Components Reference

The following codes are the codes that I use frequently. I choose _root and _parent keywords that are not used in AS3.
다음 코드는 제가 자주 사용하는 코드로, AS3에서는 사용되지 않는 _root, _parent 키워드를 사용합니다.
下のコードは私がよく使うこーどで、私はAS3では使わない_rootと_parentキーワードを選びました。
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
package{
 
	import	flash.display.MovieClip;
	import	flash.events.Event;// added on 2011.03.24
 
	public class SomeClass extends MovieClip{
 
		private var _root:MovieClip;
		private var _parent:MovieClip;
 
		public function SomeClass(){
 
			addEventListener(Event.ADDED_TO_STAGE, initialize);
 
		}// end SomeClass constructor
 
 
		/**
		 * Initializes the SomeClass, when an instance is added to the display list
		 */
		private function initialize(evt:Event):void{
 
			removeEventListener(Event.ADDED_TO_STAGE, initialize);
 
			_root = root as MovieClip;
			_parent = parent as MovieClip;
 
		}// end initialize
 
	}// end SomeClass definition
 
}// end package
Nov 282007
 
Yesterday, jin_u told me about Tweener. Tweener is an open source(MIT License) library for tweening in ActionScript 2 and 3. It has more features than the Flash native Tween class.

For more informaton, visit the official website at Google Code and Tweener Documentation and Language Reference.

어제 사내 스터디에서 진우Tweener에 대해서 알려주었습니다. Tweener는 액션스크립트 2와 3에서 트위닝을 위한 오픈소스(MIT 라이센스) 라이브러리입니다. 플래시 내장 Tween 클래스보다 많은 기능을 가지고 있네요.

자세한 정보는 Google Code의 공식 홈페이지Tweener 도움말을 참고하세요.

昨日jin_uからTweenerについて聴いた。Tweenerはオープンソース(MIT License)ライブラリーとしてtweening機能を提供します。このクラスはフラッシュ内蔵クラスより機能が多いんです。

詳しい情報はGoogle Codeの公式ホームページ、またはTweenerマニュアルへ…

 
You can add ActionScript codes to a specific frame using MovieClip.addFrameScript() method. The method is not documented, like setTimeout in the earlier version. And, mind that the frame numbering is zero-based.
특정 프레임에서 다른 프레임에 액션스크립트를 지정할 수 있는 메소드가 있었네요. MovieClip.addFrameScript()가 바로 이런 기능을 하는 메소드인데, 액션스크립트 도움말에는 포함되어 있지 않은, 미공개 메소드입니다 (이전 버전의 setTimeout 처럼 말이죠). 단, 프레임 번호는 0부터 시작한다는 것만 주의하면 됩니다.
特定フレームにActionScriptコードを追加出来るメソッドが在ったんですね。それはMovieClip.addFrameScript()です。このメソッドはヘルプには記載されていません。(以前バーゾンのsetIntervalのように…)。ただ、フレーム番号は0から始まるんですよ。
1
2
3
4
5
6
7
8
stop();
 
function frameEvent():void{
	 tf.text = "This textfield is on frame 2.";
}
addFrameScript(1, frameEvent);
 
gotoAndStop(2);

Download addFrameScript.fla

via FlashGuru Consulting

 
I made a watermark effect. I added addWatermark() method to BMPFunctions.as file which I revealed earlier. You can download the class file from the following link.
비트맵데이터에 워터마크를 넣는 효과를 만들어 보았습니다. 전에 공개한 BMPFunctions.as 클래스 에 addWatermark() 메소드를 추가한 것으로, 아래 링크에서 BMPFunctions.as 파일을 다운로드 하세요.
BitmapDataにウオーターマークを増すエフェクトを作ってみました。以前に公開したBMPFunctions.asクラスにaddWatermark()メソッド追加したんです。下のリンクからBMPFunctions.asファイルをダウンロードします。

http://hangunsworld.com/classes/com/hangunsworld/as3/util/

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
import	com.hangunsworld.as3.util.BMPFunctions;
 
var wm:BitmapData = new WatermarkSource(0, 0);
 
var bd:BitmapData = new BitmapData(mc.width, mc.height, true, 0×00);
bd.draw(mc);
 
var bmp:Bitmap = new Bitmap(bd);
bmp.x = mc.width + 5;
addChild(bmp);
 
add_btn.addEventListener(MouseEvent.CLICK, btnClick);
function btnClick(evt:MouseEvent):void{
	var mar:uint = uint(margin_txt.text);
	var off:uint = uint(offset_txt.text);
	var sca:Number = uint(scale_txt.text);
	var rot:uint = uint(rotation_txt.text);
	rot = rot%360;
	rotation_txt.text = rot.toString();
	var alp:Number = uint(alpha_txt.text);
	alp = Math.min(alp, 100);
	alpha_txt.text = alp.toString();
 
	sca /= 100;
	alp /= 100;
 
	bd.draw(mc);
	bd = BMPFunctions.addWatermark(bd, wm, mar, off, sca, rot, alp);
}

Download FLA

Oct 082007
 
I added floodFill() to the BMPFunctions.as, released yesterday. This method is an enhanced version of BitmapData.floodFill(). It changes pixels similar to the selected pixel’s color. And you can choose the contiguous option.

You can download the BMPFunctions.as file in the following link.

어제 공개한 BMPFunctions.as 클래스에 BitmapData.floodFill() 메소드를 개선한 floodFill() 메소드를 추가했습니다. 선택한 좌표의 픽셀과 비슷한 색상의 픽셀들을 원하는 색상으로 변경할 수 있습니다. 또한 연속된 영역만 변경하도록 선택할 수 있습니다.

클래스 파일은 아래 페이지에서 BMPFunctions.as를 다운로드하면 됩니다.

昨日公開したBMPFunctions.asクラスにfloodFill()メソッドを追加したんです。これはBitmapData.floodFill()メソッドを改善したので、つながっている領域だけを変更するか、イメージ全体的に変更するか選択できます。

下のリンクのページで BMPFunctions.asファイルをダウンロードできます。

http://hangunsworld.com/classes/com/hangunsworld/as3/util/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import com.hangunsworld.util.BMPFunctions;
 
var bd:BitmapData = new BitmapData(mc.width, mc.height, true, 0×00000000);
bd.draw(mc);
 
var bmp:Bitmap = new Bitmap(bd);
addChild(bmp);
bmp.x = mc.width;
 
mc.buttonMode = true;
mc.addEventListener(MouseEvent.CLICK, mcClicked);
function mcClicked(evt:MouseEvent):void{
	bd.draw(mc);
	var c:uint = bd.getPixel32(mc.mouseX, mc.mouseY);
	c1_txt.text = c.toString(16).toUpperCase();
	var c2:uint = uint(“0x” + c2_txt.text);
	var t:uint = Math.max(0, Math.min(255, uint(t_txt.text)));
	var cont:Boolean = cont_cb.selected;
 
	bd = BMPFunctions.floodFill(bd, mc.mouseX, mc.mouseY, c2, t, cont);
}

Download FLA

© 2011 Hangun's World - Blog Suffusion theme by Sayontan Sinha