2010-02-06 4 views
0

두 개의 이벤트, 하나의 mouseclick 이벤트 및 하나의 사용자 정의 이벤트를 수신하는 DrawPlaybook이라는 함수가 있습니다. 나는이 같은 "onClickHandler"내에서 사용자 정의 이벤트를 호출 할 계획입니다Flex 3 Customevent가 전달되지 않음

public function DrawPlaybook(...):void 
{ 
    //...... other stuff 
    panel.addEventListener(MouseEvent.CLICK, 
     function(e:MouseEvent){onClickHandler(e,this.panel)}); 
    panel.addEventListener(CustomPageClickEvent.PANEL_CLICKED, 
     onCustomPanelClicked); 
} 

:

package 
{ 
    import flash.events.Event; 

    import mx.containers.Panel; 

    public class CustomPageClickEvent extends Event 
    { 
     public var panelClicked:Panel; 

     // Define static constant. 
     public static const PANEL_CLICKED:String = "panelClicked"; 

     public function CustomPageClickEvent(type:String){ 
      super(type); 
      //panelClicked = panel; 
     } 

     // Override the inherited clone() method. 
     override public function clone():Event { 
      return new CustomPageClickEvent(type); 
     } 

     public function getPanelSource():Panel{ 
      return panelClicked; 
     } 
    } 
} 

문제가 있다는 것입니다 : 여기

public function onClickHandler(e:MouseEvent,panel):void 
{ 
    var eventObj:CustomPageClickEvent = new CustomPageClickEvent("panelClicked"); 
    eventObj.panelClicked = panel; 
    dispatchEvent(eventObj); 
} 

private function onCustomPanelClicked(e:CustomPageClickEvent):void { 
    Alert.show("custom click"); 
} 

을 그리고는 CustomPageClickEvent의 클래스 정의입니다 "onCustomPanelClicked"는 전혀 호출되지 않습니다. 내가 놓친 것을 눈치 채면 알려주세요.

답변

2

당신이 패널 CustomPageClickEvent에 대한 이벤트 리스너를 등록한 때문입니다,하지만 당신은 그냥이 변경 DrawPlaybook

에서 파견하고이에

var eventObj:CustomPageClickEvent = new CustomPageClickEvent("panelClicked"); 
eventObj.panelClicked = panel; 
dispatchEvent(eventObj) 

:

var eventObj:CustomPageClickEvent = new CustomPageClickEvent("panelClicked"); 
eventObj.panelClicked = panel; 
panel.dispatchEvent(eventObj) 

... 또는 이벤트 수신기를 this.addEventListener(CustomPageClickEvent.PANEL_CLICKED, onCustomPanelClicked);으로 변경하십시오.

작동하는지 알려주세요.

+0

이벤트 리스너를 다음으로 변경하십시오. this.addEventListener (CustomPageClickEvent.PANEL_CLICKED, onCustomPanelClicked); 작품입니다. 도와 주셔서 정말로 고맙습니다. – user267530

관련 문제