title: How do I dispatch a custom event from an actionscript 3 class and listen for it in the document root?
body: <p>I built a custom event dispatcher that passes variables.   I dispatch the event and then I try to listen for the event in my document root, but I never receive the event.  How do I bubble the event up to my document class?</p>
  
  <pre><code>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);
      };
  }
  
  
  }
  </code></pre>
  
  <p>The pinClicked event that is being dispatched is nested two levels deep in classes.  I add an instance of class ZoomifyViewer to the stage.  ZoomifyViewer adds and instance of ZoomGrid to the stage and ZoomGrid dispatches the event.</p>
  
  <p>When I add the same event listener and handler function directly into my ZoomGrid class (the same class that the event is dispatched from), then the listener and handler work properly.  However, when the listener and handler are in a parent class or on the stage, I get no response.</p>
  
  <p>Is a dispatcher necessary to bubble up to bubble up?</p>
  
  <p>Also, are these two lines functionally identical based on the constant pinClicked that is defined in my CustomVarEvent?</p>
  
  <pre><code> dispatchEvent(new CustomVarEvent(CustomVarEvent.pinClicked, hotspotData._name));
  
   dispatchEvent(new CustomVarEvent("pinClicked", hotspotData._name));
  </code></pre>