An event is just a message object.  Just because one gets created
successfully does not mean it is being delivered.  dispatchEvent() is a
method of the EventDispatcher class, which is a superclass of many classes,
including DisplayObject.  You need to listen for the event (with
addEventListener()) on the same EventDispatcher where the event was
dispatched. (Except in the case of events that bubble, but that's another
topic.)

For example:

public class MyWindowHolder extends Sprite {
  public function init(): void {
    var a: MyWindow = new MyWindow();
    a.addEventListener( MyEvent.EXCLAMATION, onExclamation );
  }

  private function onExclamation( event: MyEvent ): void {
    trace("ouch!");
  }
}

public class MyWindow extends Sprite {
  private function injury(): void {
    this.dispatchEvent( new MyEvent( MyEvent.EXCLAMATION ));
  }
}

Hope this helps,
Dave

On 12/18/08, Lehr, Ross (N-SGIS) <ross.l...@lmco.com> wrote:
>
> Hey All...
>
>      I'm having trouble with a custom event listener.  I'm working on
> experiment browser project trying to learn as3, OOP, and AIR.  I
> broadcasting the URL after a web page is loaded and I need a text box to
> listen for it.  I've added a trace to me urlLoadedEvent class and I know
> the URL is getting there (so, I think it's getting broadcasted ok), but
> it's not getting to the text box.  I think I have my listener in the
> wrong place, but not sure where to put it.  I don't have my exact code
> here, but below are some code snippets.  Thanks for any and all help.
>
> Ross
>
>
>
> ------ DISPACTING  EVEN
>
> In a loadComplete function urlLocation = text field for the URL string
>
>         dispatchEvent(new urlLoadEvent(urlLocation.text));
>
> ------ urlLoadEvent Class (when I trace urlLocation I am getting the URL
> string)
>
> package
> {
>         import flash.events.*;
>
>         public class urlLoadEvent extends Event
>         {
>                 public static const URL_CHANGED = "urlChanged";
>                 public var urlLocation:String;
>
>                 public function urlLoadEvent(urlL:String):void
>                 {
>                         super(URL_CHANGED);
>                         urlLocation = urlL;
>                         trace(urlLocation);
>                 }
>
>         }
> }
>
> ------ I'm not sure where to attach this.
>
> ???????.addEventListener(urlLoadEvent.URL_CHANGED, onURLChange);
> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to