0 Replies Latest reply on Jan 29, 2007 2:57 PM by

    adding easing to attached Movie Clips

      I've attached some MovieClips to the stage by looping through an array. (dreamarray) I'm trying now to add easing to each of these MovieClips. I found a tutorial, but can't seem to translate their tutorial over to my file. In the released() function...i am creating a temp variable "t" to hold each of my dream elements. The t.xPos and t.yPos are undefined when I trace them after clicking on them. I would appreciate any help!

      Right now I have t.xPos = dream._x --- I'm sure this needs to be changed

      import mx.utils.Delegate
      import mx.transitions.Tween;
      import mx.transitions.easing.*;

      var numClouds:Number = 35;
      var fl:Number = 250;
      var gravity:Number = .5;
      var vx:Number = 0;
      var vy:Number = 0;
      var vz:Number = 0;
      var friction:Number = .97;
      var vpX:Number = Stage.width / 2;
      var vpY:Number = Stage.height / 2;
      var vpY:Number = 400;
      var home:MovieClip = this;

      var dreamarray:Array = new Array();
      dreamarray[0] = "dreamone";
      dreamarray[1] = "dreamtwo";
      dreamarray[2] = "dreamthree";
      dreamarray[3] = "dreamfour";
      dreamarray[4] = "dreamfive";

      var dreamarrayX:Array = new Array();
      dreamarrayX[0] = 0
      dreamarrayX[1] = -1800;
      dreamarrayX[2] = 2000;
      dreamarrayX[3] = 100;
      dreamarrayX[4] = -1700;

      var dreamarrayZ:Array = new Array();
      dreamarrayZ[0] = 0;
      dreamarrayZ[1] = 500;
      dreamarrayZ[2] = 1000;
      dreamarrayZ[3] = 1500;
      dreamarrayZ[4] = 2000;

      function init() {
      for (var i:Number = 0; i<dreamarray.length; i++) {
      var dream:MovieClip = attachMovie(dreamarray , "dreamarray" + i, i);
      //var dream:MovieClip = attachMovie("dreamone", "dreamone" + i, i);
      //dream.x = Math.random() * 1600 - 800 + dreamoffset;
      dream.x = dreamarrayX
      ;
      dream.y = 50;
      dream.z = dreamarrayZ ;
      dream.onPress = released;
      }
      }

      function inittwo() {
      //set Number to more than number of dreams
      for (var j:Number = 20; j<numClouds; j++) {
      var cloud:MovieClip = attachMovie("cloud", "cloud" + j, j);
      //tree.x = 400;
      cloud.x = Math.random() * 2000 - 800;
      cloud.y = 50;
      cloud.z = 0 + cloudoffset;
      cloudoffset += 600;
      }
      }

      function released() {
      for (var i=0;i<dreamarray.length;i++){
      //var t:MovieClip = home["dreamarray"+i];
      var t:MovieClip = dreamarray
      ;
      //These t. values are undefined when I click on one of the attached dreamarray MovieClips
      t.xPos = dream._x;
      t.yPos = dream._y;
      t.theScale = dream._xscale;
      if (dream != this._parent)
      {
      var tw:Tween = new Tween(t, "._x", Strong.easeOut, t._x, 300, 100, true);
      }
      trace(t);
      trace(t.xPos);
      trace(t.yPos);
      }
      }


      function onEnterFrame():Void {
      //if (dreamarray4.z >= 500 && Key.isDown(Key.UP)){
      if (zdepth < 55 && Key.isDown(Key.UP)){
      vz -= 1;
      zdepth += 1;
      }

      //if(dreamarray4.z >=2000 && Key.isDown(Key.DOWN))
      if(zdepth > 0 && Key.isDown(Key.DOWN))
      {
      vz += 1;
      zdepth -= 1;
      }

      //Killed side to side motion
      /*if(Key.isDown(Key.LEFT ) )
      {
      vx += 1;
      }
      if(Key.isDown(Key.RIGHT))
      {
      vx -= 1;
      }
      if(Key.isDown(Key.SPACE))
      {
      vy += 1;
      }
      */


      vy -= gravity;
      vx *= friction;
      vy *= friction;
      vz *= friction;
      for (var i:Number=0;i<dreamarray.length;i++) {
      //i think there is a error here
      var dream:MovieClip = this["dreamarray" +i];
      dream.x += vx;
      dream.y += vy;
      dream.z += vz;
      if(dream.y < 50)
      {
      dream.y = 50;
      vy = 0;
      }

      /*if (dream.z <= -fl) {
      //delete dream.z
      dream.z_visible = false;
      }
      else if(dream.z > 3000 - fl)
      {
      dream.z._visible = true;
      }
      */

      if (dream.z <= -fl) {
      //delete dream.z
      dream.z._visible = false;
      }
      else
      {
      dream.z._visible = true;

      var scale:Number = fl / (fl + dream.z);
      dream._xscale = dream._yscale = scale*100;
      dream._x = vpX + dream.x * scale/2;
      dream._y = vpY + dream.y * scale/2;
      //dream._x = dream.x * scale/2;
      dream._alpha = scale * 60 + 40;
      dream.swapDepths(-dream.z);
      }
      }
      for (var j:Number=0;j<numClouds;j++) {
      var cloud:MovieClip = this["cloud" + j];
      cloud.x += vx;
      cloud.y += vy;
      cloud.z += vz;
      if(cloud.y < 50)
      {
      cloud.y = 50;
      vy = 0;
      }
      if (cloud.z <= -fl) {
      cloud.z += 5000;
      }
      else if(cloud.z > 5000 - fl)
      {
      cloud.z -= 5000;
      }

      var scale:Number = fl / (fl + cloud.z);
      cloud._xscale = cloud._yscale=scale*200;
      cloud._x = vpX + cloud.x * scale;
      cloud._y = vpY + cloud.y * scale;
      cloud._alpha = scale * 60 + 40;
      cloud.swapDepths(-cloud.z);
      }
      }

      init();
      inittwo();


      stop();