8 Replies Latest reply on Nov 8, 2010 2:41 AM by nikos101

    loop through the d-list in flex 4

    nikos101 Level 2

      I would like to loop through the d-list and apply the following code to every button, checkbox and drop down in my app

       

      mouseOver="animateHover('theComponentID')"

       

      how can this be done?

        • 1. Re: loop through the d-list in flex 4
          David_F57 Level 5

          hi,

           

          This should do what you want, you need to add the eventlistener now your animate can be run from th event handler.

           

          protected function button1_clickHandler(event:MouseEvent):void

          {

          for (var i:Number=0;i < this.numElements;i++)

          {

          var obj:Object = this.getElementAt(i);

          if (flash.utils.getQualifiedClassName(obj) == "spark.components::Button")

          {

          (obj as Button).addEventListener(MouseEvent.MOUSE_OVER,onMouseOver);

           

          }

          if (flash.utils.getQualifiedClassName(obj) == "spark.components::CheckBox")

          {

          (obj as CheckBox).addEventListener(MouseEvent.MOUSE_OVER,onMouseOver);

           

          }

          }

          }

           

          private function onMouseOver(event:MouseEvent):void

          {

            animateHover(event.currentTarget);

          }

          • 2. Re: loop through the d-list in flex 4
            nikos101 Level 2

            thx mate, heres the class im using for this, enjoy

            its really cool for re-using transitions

             

             

            package nikos
            {
                import mx.effects.Effect;
                import mx.effects.Sequence;
                import mx.events.EffectEvent;
               
                import spark.effects.AnimateTransitionShader;
                import spark.effects.Move3D;
                import spark.effects.Rotate3D;
                import spark.effects.animation.RepeatBehavior;

             

                public class CustomTransitions
                {
                    //+
                    public var rotateY90_CEN:Rotate3D = new Rotate3D;
                    public var rotateY360_CEN:Rotate3D = new Rotate3D;
                   
                   
                    public var rotateY0to180:Rotate3D = new Rotate3D;
                   
                    public var rotateY180to0:Rotate3D = new Rotate3D;
                   
                   
                    //-
                   
                    public var rotateY_180to0:Rotate3D = new Rotate3D;
                   
                   
                   
                   
                    public var buttonZoomOut:Move3D = new Move3D;
                   
                   
                    //pixel blender
                   
                    [Embed(source="nikos/pixelBlender/Twist.pbj", mimeType="application/octet-stream")]
                    private var TwistCodeClass:Class;

             

                   
                    public var twistShader:AnimateTransitionShader = new AnimateTransitionShader;
                   
                    private var animatingTargets:Object = new Object();
                   
               
                   
                   
                    private function animateHover(target:Object):void
                    {
                        if (animatingTargets[target.id] === undefined)
                        {
                            var effect:Effect;               
                            effect = buttonZoomOut;
                            effect.target = target;
                            animatingTargets[target.id] = effect;
                            effect.play();
                        }
                    }
                   
                   
                    //need to keep track of this so its not repeated
                    private function effectEndHandler(event:EffectEvent):void
                    {
                        delete animatingTargets[event.effectInstance.target.id];
                    }
                         
                         
                   
                    public function CustomTransitions()
                    {
                       
                        buttonZoomOut.duration = 200;
                        buttonZoomOut.zBy= -10;
                        buttonZoomOut.repeatBehavior= RepeatBehavior.REVERSE;
                        buttonZoomOut.autoCenterTransform = true;
                        buttonZoomOut.addEventListener(EffectEvent.EFFECT_END,effectEndHandler);
                       
                        //+Y rotations
                        rotateY90_CEN.angleYFrom= 0;
                        rotateY90_CEN.angleYTo= 90;
                        rotateY90_CEN.duration=900;
                        rotateY90_CEN.autoCenterTransform=true;
                       
                       
                        rotateY0to180.angleYFrom= 0;
                        rotateY0to180.angleYTo= 180;
                        rotateY0to180.duration=900;
                       
                       
                        rotateY180to0.angleYFrom= 180;
                        rotateY180to0.angleYTo= 0;
                        rotateY180to0.duration=900;
                   
                       
                       
                        rotateY360_CEN.angleYFrom= 0;
                        rotateY360_CEN.angleYTo= 360;
                        rotateY360_CEN.duration=900;
                        rotateY360_CEN.autoCenterTransform=true;
                       
                       
                        //+Y rotations
                       
                       
                       
                        rotateY_180to0.angleYFrom= -180;
                        rotateY_180to0.angleYTo= 0;
                        rotateY_180to0.duration=900;
                       
                       
                        //pb
                        twistShader.shaderByteCode = TwistCodeClass;
                        twistShader.duration=1500;
                       
                       
                    }
                   
                   
                    public function  test(target:Object):void{
                       
                        var se:Sequence = new Sequence;
                        se.addChild(rotateY0to180);
                        se.addChild(rotateY180to0);     
                        se.play([target]);
                       
                    }
                   
                   
               
                    //+
                    public function  animateRotateY90_CEN(target:Object):void{
                        var effect:Effect;               
                       
                        effect = rotateY90_CEN;
                        effect.target = target;
                       
                        effect.play();
                       
                    }
                   
                    public function  animateRotate0to180(target:Object):void{
                        var effect:Effect;               
                       
                        effect = rotateY0to180;
                        effect.target = target;
                       
                        effect.play();
                       
                    }
                   
                    public function  animateRotate180to0(target:Object):void{
                        var effect:Effect;               
                       
                        effect = rotateY180to0;
                        effect.target = target;
                       
                        effect.play();
                       
                    }
                    public function  animateRotateY360_CEN(target:Object):void{
                        var effect:Effect;               
                       
                        effect = rotateY360_CEN;
                        effect.target = target;
                       
                        effect.play();
                       
                    }
                   
                    //-
                    public function  animateRotate_180to0(target:Object):void{
                        var effect:Effect;               
                       
                        effect = rotateY_180to0;
                        effect.target = target;
                       
                        effect.play();
                       
                    }
                   
                    public function  animateTwistShader(target:Object):void{
                        var effect:Effect;               
                       
                        effect = twistShader;
                        effect.target = target;
                       
                        effect.play();
                       
                    }
                   
                   
                   
                }
            }

            • 3. Re: loop through the d-list in flex 4
              nikos101 Level 2

              that way I can apply my effects to all my buttons in the screen at once


              • 4. Re: loop through the d-list in flex 4
                David_F57 Level 5

                hi,

                 

                Have you started using pixelbender yet or just getting used to the existing filters available....

                 

                 

                David.

                1 person found this helpful
                • 5. Re: loop through the d-list in flex 4
                  nikos101 Level 2

                  unfortunately that does not do fully recursive loop, only the child directly below the stage

                  • 6. Re: loop through the d-list in flex 4
                    David_F57 Level 5

                    hi,

                     

                    I'll have a look at doing a recursive function for the whole app some time over the weekend.

                     

                     

                    David.

                    1 person found this helpful
                    • 7. Re: loop through the d-list in flex 4
                      nikos101 Level 2

                      awesome dude


                      • 8. Re: loop through the d-list in flex 4
                        nikos101 Level 2

                        Did you ever get a chance to look at this one David?