플밍

target 과 currentTarget 본문

프로그래밍/Flash & Flex

target 과 currentTarget

너구리안주 2009. 7. 29. 17:57
target 은 이벤트를 발생시킨 대상 (이벤트를 dispatch 시킨 놈)이고
currentTarget 은 이벤트 청취자이자다.

아래 소스를 실행해보면 긴말 필요없이 이해 될듯...

 


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="init()"
 verticalScrollPolicy="off" horizontalScrollPolicy="off" width="341" height="422">
 <mx:Script>
  <![CDATA[
   private function init():void{
   
    c1.addEventListener(MouseEvent.CLICK, viewResult);
   }
   
   private function viewResult(event:MouseEvent):void{
    txtTarget.text = event.target.id;
    txtCurrent.text = event.currentTarget.id;
   }
   
  ]]>
 </mx:Script>
 <mx:VBox id="c1" width="285" height="303" backgroundColor="#F61111">
  <mx:VBox id="c2" width="195" height="166" backgroundColor="#8900FE" label="c2">
   <mx:Label text="c2" fontSize="20"/>
  </mx:VBox>
  <mx:Label text="c1" fontSize="20"/>
 </mx:VBox>
 <mx:HBox width="289" height="29">
  <mx:Label text="target          "/>
  <mx:TextInput id="txtTarget"/>
 </mx:HBox>
 <mx:HBox width="289" height="34">
  <mx:Label text="currentTarget"/>
  <mx:TextInput id="txtCurrent"/>
 </mx:HBox>
</mx:Application>
Comments