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

    dynamic target for spark Animate?



      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:mx="library://ns.adobe.com/flex/mx"   >
              <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"/>
                  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);


                  public function clickHandler(event:MouseEvent):void {
                      myTextArea.text += "\rclickHandler fired: "+event.currentTarget.id;
                      myTween.targets = event.currentTarget.id;
              <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:TextArea id="myTextArea"  y="82" width="430" height="100" x="4"/>
              <s:HGroup id="myGroup">


      Any help would be appreciated!