4 Replies Latest reply on Mar 29, 2011 7:01 PM by Shongrunden

    dynamic target for spark Animate?

    digsafe

      Hi.

      I'm trying to figure out how to assign a spark Animate object a target dynamically from an Actionscript function.

      The desired result would be to have the images that are created scale when clicked.

      Here is what I have;

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                     xmlns:s="library://ns.adobe.com/flex/spark"
                     xmlns:mx="library://ns.adobe.com/flex/mx"   >
         
          <fx:Declarations>
              <s:Animate id="myTween" duration="1000">
                  <s:SimpleMotionPath property="scaleX"  valueFrom="1.0" valueTo="1.5"/>
                  <s:SimpleMotionPath property="scaleY"  valueFrom="1.0" valueTo="1.5"/>
              </s:Animate>
          </fx:Declarations>
         
          <fx:Script>
              <![CDATA[
                  import mx.controls.Image;
                  import mx.utils.ObjectUtil;

       

                  private var numOfImgs:Number = 4;

       

                  private function buildImgs():void{
                      var i:int;
                      for(i; i<numOfImgs;i++){
                          var myImg:Image = new Image;
                          myImg.id="myImg_" +ObjectUtil.toString(i);
                          myImg.addEventListener(MouseEvent.CLICK, clickHandler);
                          myGroup.addElement(myImg)
                          myImg.source="assets/test_img.jpg";
                      }
                    }

       

                  public function clickHandler(event:MouseEvent):void {
                      myTextArea.text += "\rclickHandler fired: "+event.currentTarget.id;
                      myTween.targets = event.currentTarget.id;
                      myTween.play();
                   }
              ]]>
          </fx:Script>
          <s:VGroup>
              <s:Panel width="450" y="25" x="150" height="221" title="myPanel">
                  <s:HGroup id="myGroup1">
                      <s:Button id="buildImgs_btn" click="buildImgs()" label="build imgs" x="40" y="15"/>
                  </s:HGroup>
                  <s:TextArea id="myTextArea"  y="82" width="430" height="100" x="4"/>
              </s:Panel>
              <s:HGroup id="myGroup">
              </s:HGroup>
             
          </s:VGroup>   
      </s:Application>

       

      Any help would be appreciated!