1 Reply Latest reply on Sep 4, 2007 10:48 PM by Senor_Roberto

    dispatching Event ...first trial ....

    nickname_not_taken
      Hello
      .....see code next....EventTrial object will dispatch an "trialObjectCreated" event. This is caught correctly with the method test in the same object. The object "MyFirstApplication" which creates the EventTrial object also listens to the same event. But it seems it doesn't "hear" it being generated. Any idea what I did wrong...

      results showing in console:

      test dispatched from eventTrial
      event dispatche....
      [object EventTrial]
      [SWF] F:\FlexSourceData\myFirstApplication\bin\myFirstApplication-debug.swf - 1.854 bytes after decompression


      Thanks



      package{
      import flash.events.Event;
      import flash.events.EventDispatcher;

      public class EventTrial extends EventDispatcher {

      public function EventTrial(){
      this.addEventListener("trialObjectCreated",test);
      dispatchEvent(new Event("trialObjectCreated"));
      trace ("event dispatche....");
      }

      private function test(event:Event):void{
      trace("test dispatched from eventTrial");
      }
      }
      }


      package {
      import flash.display.MovieClip;
      import flash.events.Event;
      public class myFirstApplication extends MovieClip {
      private var eventTrial:EventTrial;

      public function myFirstApplication() {
      addEventListener("trialObjectCreated", show);
      eventTrial = new EventTrial();
      trace(eventTrial);
      }
      private function show(event:Event):void {
      trace ("trialObjectCreated");
      }
      }
      }
        • 1. dispatching Event ...first trial ....
          Senor_Roberto
          You need to add the listener to the EventTrial instance which is firing the event.
          I'm not sure if it will work though, since you fire the event in the constructor.

          Try this:

          - Add a method 'fire' to EventTrial which dispatches the event (and take the event dispatch out of the constructor)
          - In your myFirstApplication constructor, create an EventTrial instance and then add the event listener to that instance:

          public function myFirstApplication () {

          this.eventTrial = new EventTrial();
          this.eventTrial.addEventListener("trialObjectCreated", show);
          this.eventTrial.fire();

          }