<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>댓글 : 이벤트에 뭔가 같이 보내보자 &#8211; 커스텀 이벤트 만들고 사용해보기</title>
	<atom:link href="http://ufx.kr/blog/228/feed" rel="self" type="application/rss+xml" />
	<link>http://ufx.kr/blog/228</link>
	<description>Flash + ActionScript &#38; Design</description>
	<lastBuildDate>Wed, 16 May 2012 06:49:08 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>세계의끝가 만듬</title>
		<link>http://ufx.kr/blog/228/comment-page-1#comment-6852</link>
		<dc:creator>세계의끝</dc:creator>
		<pubDate>Mon, 06 Feb 2012 14:33:39 +0000</pubDate>
		<guid isPermaLink="false">http://ufx.kr/blog/?p=228#comment-6852</guid>
		<description>addChild() 와 null 객체 에러와는 직접 관련이 없습니다. 화면에 addChild() 되어 있지 않아도 addEventListener() 다는데는 문제 없으니까요.
굳이 표현하자면 new 와 관계 있다고 할 수 있는데요, 객체가 new 되는 시점이 서로 모순되지 않아야 null 객체 에러가 줄어들겠죠. 

&quot;null 객체 에러 예방을 위한 액션스크립트 클래스의 초기화 순서 이해하기&quot; http://ufx.kr/blog/853
위 포스트를 정독해 보시면 초기화 순서에서 꼬이지 않는 약간의 노하우를 캐치하실지도 모릅니다.
요점은, 생성자 이전, 또는 변수 선언 수준에서 모두 new 를 때리시라는것.
런타임에서 new 를 최소화 하시라는것, 이 두가지라고 할 수 있습니다.</description>
		<content:encoded><![CDATA[<p>addChild() 와 null 객체 에러와는 직접 관련이 없습니다. 화면에 addChild() 되어 있지 않아도 addEventListener() 다는데는 문제 없으니까요.<br />
굳이 표현하자면 new 와 관계 있다고 할 수 있는데요, 객체가 new 되는 시점이 서로 모순되지 않아야 null 객체 에러가 줄어들겠죠. </p>
<p>&#8220;null 객체 에러 예방을 위한 액션스크립트 클래스의 초기화 순서 이해하기&#8221; <a href="http://ufx.kr/blog/853" rel="nofollow">http://ufx.kr/blog/853</a><br />
위 포스트를 정독해 보시면 초기화 순서에서 꼬이지 않는 약간의 노하우를 캐치하실지도 모릅니다.<br />
요점은, 생성자 이전, 또는 변수 선언 수준에서 모두 new 를 때리시라는것.<br />
런타임에서 new 를 최소화 하시라는것, 이 두가지라고 할 수 있습니다.</p>
]]></content:encoded>
	</item>
	<item>
		<title>또뱅가 만듬</title>
		<link>http://ufx.kr/blog/228/comment-page-1#comment-6847</link>
		<dc:creator>또뱅</dc:creator>
		<pubDate>Mon, 06 Feb 2012 02:02:31 +0000</pubDate>
		<guid isPermaLink="false">http://ufx.kr/blog/?p=228#comment-6847</guid>
		<description>와 정말 좋은 설명 감사합니다!! 제 코드까지 보기좋게 꾸며 주셨네요 ^^

답해주신 모든 내용이 이해가 갔습니다.

그런데 만약 B보다 A를 먼저 addChild해야 하는 상황이면 어떻게 되는 건가요??

제가 Object를 던지는 방식을 dispatchEvent나 Object를 직접적으로 던지는 방법밖에 몰라서

이렇게 코드를 짜고 있는데 이런 방식을 쓰지 않고도 원하는 클래스 오브젝트에 접근하는 방법이

있는지도 좀 알려주세요 ㅎㅎ

(AS3.0 클래스 구조의 여러가지 상황에서 부모, 자식 객체의 참조 방법)에서의 내용은 

전부 쓰고 있습니다만 현재 만들고 있는 게임이 처음 만드는 게임이라

addChild된 구조가 상당히 얽혀 있는 상태라서요;;

모든 자료를 찾아가며 공부 하고 있지만 정작 필요한 내용은 없는거 같아서요 ㅎㅎ

바쁘신데 많은 질문 드려도 괜찮을진 모르겠지만

시간나시면 답변 주세요 !!

윗 댓글에 대해서 정말 감사드립니다! 많은 도움이 되었습니다 ~

수고하세요 ```</description>
		<content:encoded><![CDATA[<p>와 정말 좋은 설명 감사합니다!! 제 코드까지 보기좋게 꾸며 주셨네요 ^^</p>
<p>답해주신 모든 내용이 이해가 갔습니다.</p>
<p>그런데 만약 B보다 A를 먼저 addChild해야 하는 상황이면 어떻게 되는 건가요??</p>
<p>제가 Object를 던지는 방식을 dispatchEvent나 Object를 직접적으로 던지는 방법밖에 몰라서</p>
<p>이렇게 코드를 짜고 있는데 이런 방식을 쓰지 않고도 원하는 클래스 오브젝트에 접근하는 방법이</p>
<p>있는지도 좀 알려주세요 ㅎㅎ</p>
<p>(AS3.0 클래스 구조의 여러가지 상황에서 부모, 자식 객체의 참조 방법)에서의 내용은 </p>
<p>전부 쓰고 있습니다만 현재 만들고 있는 게임이 처음 만드는 게임이라</p>
<p>addChild된 구조가 상당히 얽혀 있는 상태라서요;;</p>
<p>모든 자료를 찾아가며 공부 하고 있지만 정작 필요한 내용은 없는거 같아서요 ㅎㅎ</p>
<p>바쁘신데 많은 질문 드려도 괜찮을진 모르겠지만</p>
<p>시간나시면 답변 주세요 !!</p>
<p>윗 댓글에 대해서 정말 감사드립니다! 많은 도움이 되었습니다 ~</p>
<p>수고하세요 &#8220;`</p>
]]></content:encoded>
	</item>
	<item>
		<title>세계의끝가 만듬</title>
		<link>http://ufx.kr/blog/228/comment-page-1#comment-6840</link>
		<dc:creator>세계의끝</dc:creator>
		<pubDate>Sun, 05 Feb 2012 10:01:14 +0000</pubDate>
		<guid isPermaLink="false">http://ufx.kr/blog/?p=228#comment-6840</guid>
		<description>B 클래스에 선언되어 있는 B형 타입의 S_B 변수는 선언만 되어있고 실제 객체가 할당되어 있지 않는 상태군요.
객체가 존재하지 않으니 D 클래스에서 addEventListener() 를 달아 보려해도 null 객체 에러가 뜰 것이고요.
이런 경우에 B 클래스의 생성자 함수에 
&lt;pre lang=&quot;actionscript3&quot;&gt;
B.S_B = this;
&lt;/pre&gt;
라고 한줄 추가하면 B클래스로 생성한 객체가 변수에 할당되어 이벤트 핸들러든 이벤트를 디스패치 하든 모두 할 수 있게 됩니다.
단, 디스패치든 이벤트 리스너든 달기 위해서는 B 클래스의 객체가 먼저 생성되어 있어야겠죠.
무슨 이야기냐면, 이 구조에서 실질적인 호스트코드는 D 클래스로 생성한 객체의 코드인데, D 객체는 A 클래스 객체가 만들어지면 동시에 자신도 만들어지고 있습니다. 만약 A 객체가 먼저 만들어지면 D클래스의 생성자 함수가 호출되어 B.S_B 변수에 addEventListener() 를 하려는 타이밍에는 B 객체가 생성되어 있으리라는 보장이 없다는 말입니다. 
실제로 Main 클래스에서 A 클래스 객체를 먼저 생성하고 계시고 있죠.
따라서 Main 클래스에서 객체를 new 하는 순서를 바꿀 필요가 있습니다.
&lt;pre lang=&quot;actionscript3&quot;&gt;
_B = new B();
_A = new A();
&lt;/pre&gt;
이렇게 말이죠.


질문하신 댓글의 코드가 보기가 불편해서(다른 분들이 보기 어려우실까 하여) 포스트 본문과 같이 Syntax Coloring 을 적용했습니다. ^^</description>
		<content:encoded><![CDATA[<p>B 클래스에 선언되어 있는 B형 타입의 S_B 변수는 선언만 되어있고 실제 객체가 할당되어 있지 않는 상태군요.<br />
객체가 존재하지 않으니 D 클래스에서 addEventListener() 를 달아 보려해도 null 객체 에러가 뜰 것이고요.<br />
이런 경우에 B 클래스의 생성자 함수에</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>0
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;">B.S_B = <span style="color: #0033ff; font-weight: bold;">this</span>;</pre></td></tr></table></div>

<p>라고 한줄 추가하면 B클래스로 생성한 객체가 변수에 할당되어 이벤트 핸들러든 이벤트를 디스패치 하든 모두 할 수 있게 됩니다.<br />
단, 디스패치든 이벤트 리스너든 달기 위해서는 B 클래스의 객체가 먼저 생성되어 있어야겠죠.<br />
무슨 이야기냐면, 이 구조에서 실질적인 호스트코드는 D 클래스로 생성한 객체의 코드인데, D 객체는 A 클래스 객체가 만들어지면 동시에 자신도 만들어지고 있습니다. 만약 A 객체가 먼저 만들어지면 D클래스의 생성자 함수가 호출되어 B.S_B 변수에 addEventListener() 를 하려는 타이밍에는 B 객체가 생성되어 있으리라는 보장이 없다는 말입니다.<br />
실제로 Main 클래스에서 A 클래스 객체를 먼저 생성하고 계시고 있죠.<br />
따라서 Main 클래스에서 객체를 new 하는 순서를 바꿀 필요가 있습니다.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>0
1
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;">_B = <span style="color: #0033ff; font-weight: bold;">new</span> B<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
_A = <span style="color: #0033ff; font-weight: bold;">new</span> A<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</pre></td></tr></table></div>

<p>이렇게 말이죠.</p>
<p>질문하신 댓글의 코드가 보기가 불편해서(다른 분들이 보기 어려우실까 하여) 포스트 본문과 같이 Syntax Coloring 을 적용했습니다. ^^</p>
]]></content:encoded>
	</item>
	<item>
		<title>또뱅가 만듬</title>
		<link>http://ufx.kr/blog/228/comment-page-1#comment-6824</link>
		<dc:creator>또뱅</dc:creator>
		<pubDate>Fri, 03 Feb 2012 06:42:18 +0000</pubDate>
		<guid isPermaLink="false">http://ufx.kr/blog/?p=228#comment-6824</guid>
		<description>아 글을 너무 헷갈리게 적었네요 ;; 

그냥 코드를 보여드리겠습니다 ㅠㅠ;;

Main 이구요!
&lt;pre lang=&quot;actionscript3&quot;&gt;
package  
{
	import flash.display.Sprite;
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;
	/**
	 * ...
	 * @author DDo
	 */
	public class Main extends Sprite
	{
		private var _B = B;
		
		private var _A = A;
		
		//static public var mainCl : Main
		
		public function Main() : void
		{
			//mainCl = this;
			
			_A = new A();
			_B = new B();
			
			this.addChild(_A);
			this.addChild(_B);
			
			parent.addEventListener(MouseEvent.CLICK, clickHandler);
			
		}
		
		private function clickHandler($e : MouseEvent) : void
		{
			//this.dispatchEvent(new ClassEvent(ClassEvent.SEND_OBJECT, this));
			_B.clickHandler();
			
		}
	}
}
&lt;/pre&gt;
A입니다.
&lt;pre lang=&quot;actionscript3&quot;&gt;
package  
{
	import flash.display.Sprite;
	/**
	 * ...
	 * @author DDo
	 */
	public class A extends Sprite
	{
		private var _C : C;
		
		private var _D : D;
		
		
		public function A() : void
		{
			_C = new C();
			_D = new D();
			this.addChild(_C);
			this.addChild(_D);
		}
	}
}
&lt;/pre&gt;
B입니다.
&lt;pre lang=&quot;actionscript3&quot;&gt;
package  
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	/**
	 * ...
	 * @author DDo
	 */
	public class B extends Sprite
	{
		static public var S_B : B;
		
		public function B() : void
		{
			
		}
		
		private function callHandler($e : ClassEvent) : void
		{
			trace($e.currentTarget);
		}
		
		public function clickHandler() : void
		{
			trace(&quot;클릭해서 B로 넘어왔음요 !&quot;);
			this.dispatchEvent(new ClassEvent(ClassEvent.SEND_OBJECT, this));
		}
	}
}
&lt;/pre&gt;
C는 아무 내용도 없이 그냥 빈것 입니다.

D입니다.
&lt;pre lang=&quot;actionscript3&quot;&gt;
package  
{
	import flash.display.Sprite;
	/**
	 * ...
	 * @author DDo
	 */
	public class D extends Sprite
	{
		
		public function D() : void
		{
			trace(B.S_B); // null이 뜹니다!
			
			B.S_B.addEventListener(ClassEvent.SEND_OBJECT, sendObject);
			// null 이므로 읽히지 않습니다...........
		}
		
		private function sendObject($e : ClassEvent) : void
		{
			trace(&quot;D 에서의 반응입니다&quot;);
			trace($e.Obj, $e.currentTarget);
		}
		
	}
}
&lt;/pre&gt;
가르쳐 주신 커스텀 이벤트의 파일 이름은 ClassEvent이구요 

data가 Obj로 변했다는 것 빼곤 모두 똑같습니다.

제가 만든 코드의 전부 입니다

Main.. 그러니까 stage에서 클릭했을때의 이벤트를 B로 보내서

B에서 dispatchEvent를 했고

그 이벤트 내용(?) 을 D에서 받고 싶어서 리스너를 작동 시켰는데 아무 반응이 없길래 

trace로 확인을 해보니 null값이 나왔습니다.;;

음.... null값이 안나와야 읽을 수 있는데 여기서 딱 막혀버렸어요 ..

D에서 받고싶은데 방법을 잘 몰라서 질문했습니다..

윗글은 신경안쓰셔도 됩니다. 글이 길어서 죄송합니다 ㅎㅎ;;</description>
		<content:encoded><![CDATA[<p>아 글을 너무 헷갈리게 적었네요 ;; </p>
<p>그냥 코드를 보여드리겠습니다 ㅠㅠ;;</p>
<p>Main 이구요!</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
34
35
36
37
38
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span>  
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">EventDispatcher</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">MouseEvent</span>;
	<span style="color: #3f5fbf;">/**
	 * ...
	 * @author DDo
	 */</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Main extends <span style="color: #004993;">Sprite</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _B = B;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _A = A;
&nbsp;
		<span style="color: #009900;">//static public var mainCl : Main</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #009900;">//mainCl = this;</span>
&nbsp;
			_A = <span style="color: #0033ff; font-weight: bold;">new</span> A<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			_B = <span style="color: #0033ff; font-weight: bold;">new</span> B<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>_A<span style="color: #000000;">&#41;</span>;
			<span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>_B<span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #004993;">parent</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">CLICK</span>, clickHandler<span style="color: #000000;">&#41;</span>;
&nbsp;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> clickHandler<span style="color: #000000;">&#40;</span>$e <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #009900;">//this.dispatchEvent(new ClassEvent(ClassEvent.SEND_OBJECT, this));</span>
			_B.clickHandler<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>A입니다.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span>  
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
	<span style="color: #3f5fbf;">/**
	 * ...
	 * @author DDo
	 */</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> A extends <span style="color: #004993;">Sprite</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _C <span style="color: #000000; font-weight: bold;">:</span> C;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _D <span style="color: #000000; font-weight: bold;">:</span> D;
&nbsp;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> A<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			_C = <span style="color: #0033ff; font-weight: bold;">new</span> C<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			_D = <span style="color: #0033ff; font-weight: bold;">new</span> D<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>_C<span style="color: #000000;">&#41;</span>;
			<span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>_D<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>B입니다.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span>  
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">Event</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">EventDispatcher</span>;
	<span style="color: #3f5fbf;">/**
	 * ...
	 * @author DDo
	 */</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> B extends <span style="color: #004993;">Sprite</span>
	<span style="color: #000000;">&#123;</span>
		static <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> S_B <span style="color: #000000; font-weight: bold;">:</span> B;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> B<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> callHandler<span style="color: #000000;">&#40;</span>$e <span style="color: #000000; font-weight: bold;">:</span> ClassEvent<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>$e.<span style="color: #004993;">currentTarget</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> clickHandler<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;클릭해서 B로 넘어왔음요 !&quot;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> ClassEvent<span style="color: #000000;">&#40;</span>ClassEvent.SEND_OBJECT, <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>C는 아무 내용도 없이 그냥 빈것 입니다.</p>
<p>D입니다.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span>  
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
	<span style="color: #3f5fbf;">/**
	 * ...
	 * @author DDo
	 */</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> D extends <span style="color: #004993;">Sprite</span>
	<span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> D<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>B.S_B<span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// null이 뜹니다!</span>
&nbsp;
			B.S_B.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>ClassEvent.SEND_OBJECT, sendObject<span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">// null 이므로 읽히지 않습니다...........</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> sendObject<span style="color: #000000;">&#40;</span>$e <span style="color: #000000; font-weight: bold;">:</span> ClassEvent<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;D 에서의 반응입니다&quot;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>$e.Obj, $e.<span style="color: #004993;">currentTarget</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>가르쳐 주신 커스텀 이벤트의 파일 이름은 ClassEvent이구요 </p>
<p>data가 Obj로 변했다는 것 빼곤 모두 똑같습니다.</p>
<p>제가 만든 코드의 전부 입니다</p>
<p>Main.. 그러니까 stage에서 클릭했을때의 이벤트를 B로 보내서</p>
<p>B에서 dispatchEvent를 했고</p>
<p>그 이벤트 내용(?) 을 D에서 받고 싶어서 리스너를 작동 시켰는데 아무 반응이 없길래 </p>
<p>trace로 확인을 해보니 null값이 나왔습니다.;;</p>
<p>음&#8230;. null값이 안나와야 읽을 수 있는데 여기서 딱 막혀버렸어요 ..</p>
<p>D에서 받고싶은데 방법을 잘 몰라서 질문했습니다..</p>
<p>윗글은 신경안쓰셔도 됩니다. 글이 길어서 죄송합니다 ㅎㅎ;;</p>
]]></content:encoded>
	</item>
	<item>
		<title>또뱅가 만듬</title>
		<link>http://ufx.kr/blog/228/comment-page-1#comment-6806</link>
		<dc:creator>또뱅</dc:creator>
		<pubDate>Wed, 01 Feb 2012 06:59:52 +0000</pubDate>
		<guid isPermaLink="false">http://ufx.kr/blog/?p=228#comment-6806</guid>
		<description>자주 질문 드려서 죄송합니다! ㅎㅎ 제가 알고싶은게 너무 많거든요~

3일동안 머리를 짜내다가 결국엔 질문 드립니다!

일단 그림으로 보여드릴게요 

                             Main
                      /        \
                    A           B
                  /   \       /   \
                C      D     E     F
              /                      \
           G                            H 

이렇게 생긴 구조가 있습니다.

Main 에서 A와 B를 addChild

A는 C와 D를 , B는 E와 F를 addChild

C는 G를 F는 H를 addChild했습니다.

Main은 도큐먼트 클래스이고 모든 as파일들은 sprite를 상속받았습니다.

따로 ClassEvent라는 커스텀 이벤트를 만들어 놓았구요 

ClassEvent의 생성자 매개변수로는 (type : String, Obj : Object)로 되어 있습니다.

bubble과 cancelable 는 생략했습니다.

그리고 나머지는 커스텀 이벤트와 똑같습니다.

여기서 Main.as의 코드 내용을 보여드리겠습니다.

public class Main extends Sprite
    {
      private var _A = A;
      private var _B = B;
		
      public var _Dispatch : EventDispatcher = new EventDispatcher();
		
      public function Main() : void
      {
	_A = new A();
	_B = new B();
			
	this.addChild(_A);
	this.addChild(_B);
			
	parent.addEventListener(MouseEvent.CLICK, clickHandler);
       }
		
       private function clickHandler($e : MouseEvent) : void
       {
       _Dispatch.dispatchEvent(new ClassEvent(ClassEvent.SEND_OBJECT, this));
       }
}

글이 짤리네요 ..

A와 B를 addChild하고 클릭했을 때 dispatchEvent를 한 상황입니다.

이떄 매개변수로 넣은 this[Onject Main] 을 H.as에서 받으려면 

어떤식으로 해야되는지 도저히 모르겠습니다.

H.as에서 public var _Dispatch : EventDispatcher = new EventDispatcher();

를 넣고 _Dispatch.addEventListener(ClassEvent.SEND_OBJECT, handler);

뭐 이런식으로 받으려고 해도 

안받아지더라구요 

H.parent.parent.parent. 막 이런식으로 parent를 남발하기가 좀 그래서 

이벤트로 Object를 보내 그걸 바로 받고 싶은데 

잘 모르겠네요 ;;

이것만 해결되면 만들던 게임이 거의 완성이 되는데 

아직 초보라 막코딩을 하는 수준이라........ 

한번 해보고 싶어서 질문 드렸습니다.

수고하세요!</description>
		<content:encoded><![CDATA[<p>자주 질문 드려서 죄송합니다! ㅎㅎ 제가 알고싶은게 너무 많거든요~</p>
<p>3일동안 머리를 짜내다가 결국엔 질문 드립니다!</p>
<p>일단 그림으로 보여드릴게요 </p>
<p>                             Main<br />
                      /        \<br />
                    A           B<br />
                  /   \       /   \<br />
                C      D     E     F<br />
              /                      \<br />
           G                            H </p>
<p>이렇게 생긴 구조가 있습니다.</p>
<p>Main 에서 A와 B를 addChild</p>
<p>A는 C와 D를 , B는 E와 F를 addChild</p>
<p>C는 G를 F는 H를 addChild했습니다.</p>
<p>Main은 도큐먼트 클래스이고 모든 as파일들은 sprite를 상속받았습니다.</p>
<p>따로 ClassEvent라는 커스텀 이벤트를 만들어 놓았구요 </p>
<p>ClassEvent의 생성자 매개변수로는 (type : String, Obj : Object)로 되어 있습니다.</p>
<p>bubble과 cancelable 는 생략했습니다.</p>
<p>그리고 나머지는 커스텀 이벤트와 똑같습니다.</p>
<p>여기서 Main.as의 코드 내용을 보여드리겠습니다.</p>
<p>public class Main extends Sprite<br />
    {<br />
      private var _A = A;<br />
      private var _B = B;</p>
<p>      public var _Dispatch : EventDispatcher = new EventDispatcher();</p>
<p>      public function Main() : void<br />
      {<br />
	_A = new A();<br />
	_B = new B();</p>
<p>	this.addChild(_A);<br />
	this.addChild(_B);</p>
<p>	parent.addEventListener(MouseEvent.CLICK, clickHandler);<br />
       }</p>
<p>       private function clickHandler($e : MouseEvent) : void<br />
       {<br />
       _Dispatch.dispatchEvent(new ClassEvent(ClassEvent.SEND_OBJECT, this));<br />
       }<br />
}</p>
<p>글이 짤리네요 ..</p>
<p>A와 B를 addChild하고 클릭했을 때 dispatchEvent를 한 상황입니다.</p>
<p>이떄 매개변수로 넣은 this[Onject Main] 을 H.as에서 받으려면 </p>
<p>어떤식으로 해야되는지 도저히 모르겠습니다.</p>
<p>H.as에서 public var _Dispatch : EventDispatcher = new EventDispatcher();</p>
<p>를 넣고 _Dispatch.addEventListener(ClassEvent.SEND_OBJECT, handler);</p>
<p>뭐 이런식으로 받으려고 해도 </p>
<p>안받아지더라구요 </p>
<p>H.parent.parent.parent. 막 이런식으로 parent를 남발하기가 좀 그래서 </p>
<p>이벤트로 Object를 보내 그걸 바로 받고 싶은데 </p>
<p>잘 모르겠네요 ;;</p>
<p>이것만 해결되면 만들던 게임이 거의 완성이 되는데 </p>
<p>아직 초보라 막코딩을 하는 수준이라&#8230;&#8230;.. </p>
<p>한번 해보고 싶어서 질문 드렸습니다.</p>
<p>수고하세요!</p>
]]></content:encoded>
	</item>
	<item>
		<title>AS3.0 클래스 구조의 여러가지 상황에서 부모, 자식 객체의 참조 방법 &#124; 세계의끝과 플래시 원더랜드가 만듬</title>
		<link>http://ufx.kr/blog/228/comment-page-1#comment-1209</link>
		<dc:creator>AS3.0 클래스 구조의 여러가지 상황에서 부모, 자식 객체의 참조 방법 &#124; 세계의끝과 플래시 원더랜드</dc:creator>
		<pubDate>Mon, 29 Mar 2010 09:35:13 +0000</pubDate>
		<guid isPermaLink="false">http://ufx.kr/blog/?p=228#comment-1209</guid>
		<description>[...] 됩니다. 커스텀 이벤트는 이 포스트의 범위를 벗어나는 내용이므로 &#8220;이벤트에 뭔가 같이 보내보자 &#8211; 커스텀 이벤트 만들고 사용해보기&#8221; 를 읽어보시기 [...]</description>
		<content:encoded><![CDATA[<p>[...] 됩니다. 커스텀 이벤트는 이 포스트의 범위를 벗어나는 내용이므로 &#8220;이벤트에 뭔가 같이 보내보자 &#8211; 커스텀 이벤트 만들고 사용해보기&#8221; 를 읽어보시기 [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

