How to send custom event from actioncript 3 class and listen to it in document root directory?

I built a custom event manager that passes variables. I send an event and then try to listen to the event at the root of my document, but I never get this event. How do I bubble an event before my document class?

addEventListener(CustomVarEvent.pinClicked, pinClickedHandler);

function pinClickedHandler(e:CustomVarEvent) {
        trace("main says " + e.arg[0] + " clicked");//access arguments array
    }

package zoomify.viewer
{
import com.maps.CustomVarEvent;
    protected function hotspotClickHandler(event:MouseEvent):void {
        var hotspotData:Hotspot = hotspotsMap[event.currentTarget] as Hotspot;
        trace(hotspotData._name + " was clicked");
        /*if(hotspotData) {
            navigateToURL(new URLRequest(hotspotData.url), hotspotData.urlTarget);
        }*/
        dispatchEvent(new CustomVarEvent("pinClicked",true,false,hotspotData._name));
    }
}
package com.maps
{
// Import class
import flash.events.Event;
// CustomVarEvent
public class CustomVarEvent extends Event {
    public static const pinClicked:String = "pinClicked";
    // Properties
    public var arg:*;
    // Constructor
    public function CustomVarEvent(type:String, ... a:*) {
        var bubbles:Boolean = true;
        var cancelable:Boolean = false;
        super(type, bubbles, cancelable);
        arg = a;

    }

    // Override clone
    override public function clone():Event{
        return new CustomVarEvent(type, arg);
    };
}

}

The pinClicked event that is dispatched is nested two levels deep in the classes. I am adding an instance of the ZoomifyViewer class to the scene. ZoomifyViewer adds a ZoomGrid instance to the scene, and ZoomGrid dispatches an event.

ZoomGrid ( , ), . , , .

?

, pinClicked, CustomVarEvent?

 dispatchEvent(new CustomVarEvent(CustomVarEvent.pinClicked, hotspotData._name));

 dispatchEvent(new CustomVarEvent("pinClicked", hotspotData._name));
+3
4

, , , DisplayObject ( DisplayObject, Sprite MovieClip), .

, , , , , , .

, , , , , , , , .


package zoomify.viewer
{
    import com.maps.CustomVarEvent;

    protected function hotspotClickHandler(event:MouseEvent):void
    {
        // BY THE WAY, event.currentTarget will return the actual object, so you
        // don't need whatever the hotspotsMap[] thing is, just cast event.currentTarget
        /*var hotspotData:Hotspot = hotspotsMap[event.currentTarget] as Hotspot;*/
        var hotspotData:Hotspot = event.currentTarget as Hotspot;

        // here we dispatch the event off of the target, since it is definitely
        // in the display list already, so therefore bubbling will work right
        event.target.dispatchEvent(new CustomVarEvent("pinClicked",true,false,hotspotData._name));
    }
}
+4

. , , , . ?

+3

Bubbling , , , . .

, , .

, , EventDispatcher, . ( ).

0

.

yourDispatcher.addEventListener(CustomVarEvent.pinClicked, pinClickedHandler);

Where your Dispatcher is the class that dispatches the custom event.

-1
source

Source: https://habr.com/ru/post/1706426/


All Articles