2 Replies Latest reply on Aug 7, 2009 11:24 AM by Chet Haase

    play effect on dynamically created visual component

    _luke_*

      Hi!

       

      Can someone please explain to me, how do I play effect on a visual component created in actionscript?

       

      Thanks, regards

        • 1. Re: play effect on dynamically created visual component
          David_F57 Level 5

          _luke_* wrote:

           

          Hi!

           

          Can someone please explain to me, how do I play effect on a visual component created in actionscript?

           

          Thanks, regards

           

          It depends on what you are try to do, if you want for instance a mouse over affect you can add the effect at the same time you create the component by adding an event listener which then plays the effect.

           

          ie.

          var myComponent: SpecialComponent = new SpecialComponent()

          myComponent.addEventListener(MouseEvent.MOUSE_OVER, runEffect);

           

          private function runEffect(event:MouseEvent): void

          {

            myEffect.play(event.currentTarget);

          }

          • 2. Re: play effect on dynamically created visual component
            Chet Haase Level 3

            You can also set the target/targets property of the effect once you've created the instance in AS, just like you do in MXML code. So where in MXML you might have something like this:

                 <mx:Button id="button" click="mover.play()"/>

                  <mx:Move id="mover" target=""/>

            you would do the equivalent in actionscript like this:

                 var button:Button = new Button();

                 var mover:Move = new Move();

                 mover.target = button;

                 button.addEventListener(MouseEvent.CLICK, clickHandler);

             

                 private function clickHandler(event:Event):void

                 {

                      mover.play();

                 }

             

            There's no mystery here in launching effects from AS - it's the same properties and structures that you set up in MXML, just different syntactic ways of referring to the properties and events.

             

            Chet.