4 Replies Latest reply on Nov 25, 2009 6:39 AM by pauland

    Trouble with events


      I have a small application which tries to send an event when it starts up.  The event is not being received by the StartupController (Application, event and receiver are below).  I'm a Java programmer, new to Flex, and I may have some misunderstanding.  I need to have a constructed StartupController object in order to receive the event.  Do I need to have a StartupController object (should one be in scope) when I dispatch the event?  Will any StartupController in memory receive the event?  Should I make the StartupController a singleton and initialize it somewhere?  Do I have to maintain a list of subscribers?  Am I confusing Java concepts with Flex?  Thanks.



      *******************  Application *******************************


      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">

                  import events.StartupEvent;
                  import controllers.StartupController;
                  public function init():void {


                      dispatchEvent(new StartupEvent(StartupEvent.STARTUP_EVENT))



      *********************** event class ****************************************


      package events
          import flash.events.Event;


          public class StartupEvent extends Event {
              public static const STARTUP_EVENT:String = "startupEvent";
              public function StartupEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false)
                  super(type, bubbles, cancelable);
              override public function clone():Event {
                  return new StartupEvent(type, bubbles, cancelable);


      ********************* event receiver (StartupController)  ********************************


      package controllers
          import entities.Person;
          import entities.Family;
          import events.StartupEvent;
          import flash.events.EventDispatcher;
           [Event(name="startupEvent", type="events.StartupEvent")]
          public class StartupController extends EventDispatcher {

              public function StartupController() {
              public function init():void {
                  addEventListener(StartupEvent.STARTUP_EVENT, respondToEvent);
              public function respondToEvent(event:StartupEvent):void {
                  var father:Person = new Person();
                  father.setBirthdate("March 1866");
                  father.setBirthLocation("Horrem, Germany");
                  father.setDeathLocation("Madison, WI");
                  var mother:Person = new Person();
                  mother.setDeathdate("about 1906");
                  mother.setDeathLocation("Town of Berry");
                  var family:Family = new Family(father, mother);