3 Replies Latest reply on May 12, 2010 10:07 AM by TeotiGraphix

    Composite Component shared event

    frszilinski

      Hi,

      I have a VBox with Button and Label as children. If the user ie. "mouses-down" the label, the button should be in state down. Same on rollover. Does somebody know how to do that?

       

      Thanks

        • 1. Re: Composite Component shared event
          TeotiGraphix Level 3

          Hi,

           

          You could achieve something close to what you want in spark with;

           

              <fx:Script>
                  <![CDATA[
                      protected function label_mouseDownHandler(event:MouseEvent):void
                      {
                          button.skin.currentState = "down";
                      }
                     
                      protected function label_mouseOverHandler(event:MouseEvent):void
                      {
                          button.skin.currentState = "over";
                      }
                     
                      protected function label_rollOutHandler(event:MouseEvent):void
                      {
                          button.skin.currentState = "up";
                      }

           

                  ]]>
              </fx:Script>

           

              <s:Button id="button" label="Button One"/>
              <s:Label id="label"
                       text="asdasdasdasdasd"
                       mouseDown="label_mouseDownHandler(event)"
                       rollOver="label_rollOverHandler(event)"
                       rollOut="label_rollOutHandler(event)"/>

           

          As far as the halo Button, it is completly mouse driven. So I don't think it's possible to do what you want with mx:Button.

           

          Mike

          1 person found this helpful
          • 2. Re: Composite Component shared event
            frszilinski Level 1

            Thanks Mike!

            Sorry for that question, it was monday.

             

            I solved it with Flex 3 like this (its so easy):

             

            ...

            private var _button:Button;

            private var _label:Label;

            ...

            label.addEventListener( MouseEvent.ROLL_OVER, doit );

            ...

            private function doit(event:MouseEvent):void {

              var rollOverEvent:MouseEvent = new MouseEvent(...) // with bubbles false

              _button.dispatchEvent( rollOverEvent );

            }

            ...

             

            And that's it! Button "reacts" on label rollOver!

            • 3. Re: Composite Component shared event
              TeotiGraphix Level 3

              Ha

               

              I didn't even think about dispatching and event through the button for Flex 3.

               

              Nice call.

               

              Mike