3 Replies Latest reply on Jun 15, 2009 12:07 PM by CoreyRLucier

    Event handler madness

    benz03

      Sorry for the title. Couldn`t think of how to call this.

       

      I have a problem with listening to events from components inside a group. I want to be able to listen for move events.

      This is my basic setup:

       


          <fx:Script>
              <![CDATA[


                  protected function newFancyButton_moveHandler(event:MoveEvent):void
                  {
                      debug_tx.text+="\n Spark Button moved "+event.target.id;
                  }

       

              ]]>
          </fx:Script>
         
         
          <s:Button label="Horizontal Layout" click="myGroup.layout = new HorizontalLayout()" />
          <s:Button label="Vertical Layout" click="myGroup.layout = new VerticalLayout()"  x="130" y="0"/>
         
          <s:Group id="myGroup" y="50">
             
             
              <s:Button id="newFancyButton" label="Spark Button" move="newFancyButton_moveHandler(event)" />
              <s:Button id="anotherButton" label="Other Button" />

       

             
          </s:Group>
          <s:TextArea id="debug_tx" x="332" y="13" height="340" width="421"/>
      </s:Application>

       

      If I run this the move handler never gets called. Now comes the interesting part!

      If I add an old mx button and also listen for his move event. The spark button calls the event but not the mx button!!!

       

      So this one:

       

          <fx:Script>
              <![CDATA[
                  import mx.events.MoveEvent;
                  import spark.layouts.VerticalLayout;
                  import spark.layouts.HorizontalLayout;
                 

       

                  protected function oldMxButton_moveHandler(event:MoveEvent):void
                  {
                      debug_tx.text+="\n MX Button moved "+event.target.id;
                  }

       


                  protected function newFancyButton_moveHandler(event:MoveEvent):void
                  {
                      debug_tx.text+="\n Spark Button moved "+event.target.id;
                  }

       

              ]]>
          </fx:Script>
         
         
          <s:Button label="Horizontal Layout" click="myGroup.layout = new HorizontalLayout()" />
          <s:Button label="Vertical Layout" click="myGroup.layout = new VerticalLayout()"  x="130" y="0"/>
         
          <s:Group id="myGroup" y="50">
             
              <mx:Button id="oldMxButton" label="MX Button" move="oldMxButton_moveHandler(event)" click="debug_tx.text+='\n'+event.target" />
              <s:Button id="newFancyButton" label="Spark Button" move="newFancyButton_moveHandler(event)" />
              <s:Button id="anotherButton" label="Other Button" />

       

             
          </s:Group>
          <s:TextArea id="debug_tx" x="332" y="13" height="340" width="421"/>

       

      result is that the Spark button correctly dispatches it`s move event but the mx button is silent.

      I`ve attached the two sample mxml files if anyone wants to check out this strange bahavior.

       

      Thanks for any insight on this

      Benz

        • 1. Re: Event handler madness
          CoreyRLucier Adobe Employee

          Silly question but, isn't it the case that (in your first example) the first button (newFancyButton) doesn't actually move when you switch layouts?

           

          e.g. In both Horizontal case and Vertical case, it's the first button, so it stays in upper left of the group.

           

          If you move the move event handler to the button below it (another Button) it gets called fine...or if you simply add another element (like you did with mx:Button) first in the list, successive button's move handler will get called..because they actually change position when you switch from the horizontal to vertical layout (but not first button).

           

          -C

          • 2. Re: Event handler madness
            benz03 Level 1

            Jesuz! I feel sad now.

            Is there a way to remove this thread nobody should see it :-)

             

            Thanks that`s it

             

            Benz

            • 3. Re: Event handler madness
              CoreyRLucier Adobe Employee

              No worries.  That's why the forums are here...some times it helps to get a second set of eyes to avoid pulling your hair out.