• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 395
  • Last Modified:

Custom Events and Event Handlers

I have setup up a EventDispatcher interface on an Abstract Object.  I am trying to call an event handler in the inherated object.  All of the code compiles and works, but the event will not fire.

How do you fire events from within objects.  What have I done wrong?

===================================================================================
Abstract Class, Base Object
===================================================================================
package EasterEggDesigner.DesignTools
{
      import flash.display.*
      import flash.events.*;
      import flash.net.*;
      
      public class DesignTool extends MovieClip implements IEventDispatcher
      {
            private var _IconFile:String;
            private var _IconLoader:Loader = new Loader();
            
            public static const ICON_CHANGED:String = "IconChanged";
            public static const BASE_LOADED:String = "BaseLoaded";
            
            private var dispacher:EventDispatcher = new EventDispatcher();
            
            public function set IconFile(newFile:String)
            {
                  _IconFile = newFile;
                  
                  //
                  // ABDC_TODO: Set golbal File directory
                  //
                  
                  var FileRequest:URLRequest = new URLRequest("ToolIcons/" + newFile);
                  _IconLoader.load(FileRequest);
                  addChild(IconLoader);
                  dispacher.dispatchEvent(new Event(ICON_CHANGED));
            }
            
            public function get IconFile():String
            {
                  return _IconFile;
            }
            
            public function get IconLoader():Loader
            {
                  return _IconLoader;
            }
            
            public function DesignTool()
            {
                  dispacher.dispatchEvent(new Event(BASE_LOADED));
            }
      }
}

===================================================================================
Child Class
===================================================================================

package EasterEggDesigner.DesignTools
{
      import flash.display.*;
      import flash.events.*;
      import flash.text.*;
      
      public class Sizer extends DesignTool
      {      
            public function Sizer()
            {
                  txtToolName.text = "Sizer";
                  IconFile = "Sizer.swf";
                  addEventListener(ICON_CHANGED,onIconChange);
            }
            
            public function onIconChange(event:Event):void
            {
                  trace("The Icon Has Been Loaded" + event.target);
            }
      }
}
0
hoyaabanks
Asked:
hoyaabanks
1 Solution
 
trigger-happyCommented:

 public class DesignTool extends MovieClip implements IEventDispatcher
      {
            private var _IconFile:String;
            private var _IconLoader:Loader = new Loader();
            
            public static const ICON_CHANGED:String = "IconChanged";
            public static const BASE_LOADED:String = "BaseLoaded";
            
            private var dispacher:EventDispatcher;
            
            public function set IconFile(newFile:String)
            {
                  _IconFile = newFile;
                  
                  //
                  // ABDC_TODO: Set golbal File directory
                  //
                  
                  var FileRequest:URLRequest = new URLRequest("ToolIcons/" + newFile);
                  _IconLoader.load(FileRequest);
                  addChild(IconLoader);
                  dispacher.dispatchEvent(new Event(ICON_CHANGED));
            }
            
            public function get IconFile():String
            {
                  return _IconFile;
            }
            
            public function get IconLoader():Loader
            {
                  return _IconLoader;
            }
            
            public function DesignTool()
            {
                  dispacher = new EventDispatcher();
                  dispacher.dispatchEvent(new Event(BASE_LOADED));
            }
      }
}
 
package EasterEggDesigner.DesignTools
{
      import flash.display.*;
      import flash.events.*;
      import flash.text.*;
      
      public class Sizer extends DesignTool
      {      
            public function Sizer()
            {
                  super();
                  txtToolName.text = "Sizer";
                  IconFile = "Sizer.swf";
                  addEventListener(ICON_CHANGED,onIconChange);
            }
            
            public function onIconChange(event:Event):void
            {
                  trace("The Icon Has Been Loaded" + event.target);
            }
      }
}

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now