2 Replies Latest reply on Mar 10, 2011 11:39 AM by Rahul7777

    dispatching events between components/main application problem

    Rahul7777

      Hi ,

           i am new to flex, i am working hard to learn event dispatching, i got some knowledge but still not clear. Firstly i started dispatching events between components, later between main application and components, first one works, but later one didn't.

      Can you go through it and help me out.

       

       

      MainApp.mxml

      <s:application>

       

      <fx:Metadata>
              [Event(name="RebatesChangedEvent", type="flash.events.Event")]
          </fx:Metadata>

       

      <fx:Script>

                import events.ChangeEvent;

         protected function one_clickHandler(event:MouseEvent):void

      {

            dispatchEvent(new RebatesChangeEvent("ChangedEvent"));

      }

       

      </fx:Script>

      <mx:checkBox id="one"  click="one_clickhandler(event)"/>

       

      <comps:Rectangle id="rect"    x="10" y="50" />

      </s:application>

       

       

      Rectangle.mxml

       

      <s:Group intialize="init()">

      <fx:script>

      import event.ChangeEvent;

      public function init():void

      {
        parent.addEventListener(ChangeEvent.change,eventListener);

      }

      public function eventListener(event:Event):void

      {

          alert.show("event Dispatched");

      }

      <s:rect> <s:fill> <s:SolidColor color="blue" alpha="0.3"/>

      </s:fill> </s:Rect>

      </s:Group>

       

       

      ChangeEvent.mxml

       

      public class ChangeEvent extends Event
          {
              public  static const rebates:String = "ChangedEvent";
              public function ChangeEvent(type:String)
              {
                  super(type);
              }
           public override function  clone():Event
           {
               var event:ChangeEvent =  new ChangeEvent(type);
               return event;
           }
          }

       

       

      Here while adding the listener i used parent.addeventListener(...)  i am not sure when to use parent, while dispatching b/w components this works but not b/w application and component.

       

      Can any one help me out.

       

      thanks

      for reading.