开发者

Flex 3 Customevent not getting dispatched

I have a function called DrawPlaybook which listens to two events, one mouseclick event and one custom event.

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

I am planning to call the custom event from within "onClickHandler" like this:

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");
}

And here is the class definition for CustomPageClickEvent:

package
{
    import flash.events.Event;

    import mx.containers.Panel;

    public class CustomPageClickEvent extends E开发者_JS百科vent
    {
        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;
        }
    }
}

The issue is that "onCustomPanelClicked" never gets invoked at all. Please let me know if you notice anything that I missed.


It's because you have registered the event listener for CustomPageClickEvent on the Panel, but you're dispatching it from DrawPlaybook

Just change this:

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

to this:

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

... or change the event listener to this.addEventListener(CustomPageClickEvent.PANEL_CLICKED, onCustomPanelClicked);.

Let me know if that works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜