3 Replies Latest reply on Jan 25, 2007 12:40 PM by kglad

    Modify script to attach different MovieClips

      I need to figure out how to modify this code to be able to load different movie clips instead of 100 of the same. The idea is to make a nav from this. So i only want to load one, "tree"....then I want to attach a completely different movie clip to the staged a different fixed x,y,z value.

      The script I have is:

      var numTrees:Number = 10;
      var fl:Number = 250;
      var gravity:Number = .5;
      var vx:Number = 0;
      var vy:Number = 0;
      var vz:Number = 0;
      var friction:Number = .98;
      var vpX:Number = Stage.width / 2;
      var vpY:Number = Stage.height / 2;

      init();
      function init() {
      for (var i:Number = 0; i<numTrees; i++) {
      var tree:MovieClip = attachMovie("tree", "tree" + i, i);
      tree.x = Math.random() * 2000 - 1000;
      tree.y = 50;
      tree.z = Math.random() * 10000;
      }
      }

      function onEnterFrame():Void {
      if(Key.isDown(Key.UP))
      {
      vz -= 1;
      }
      else if(Key.isDown(Key.DOWN))
      {
      vz += 1;
      }
      if(Key.isDown(Key.LEFT))
      {
      vx += 1;
      }
      else 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<numTrees;i++) {
      var tree:MovieClip = this["tree" + i];

      tree.x += vx;
      tree.y += vy;
      tree.z += vz;
      if(tree.y < 50)
      {
      tree.y = 50;
      vy = 0;
      }
      if (tree.z <= -fl) {
      tree.z += 10000;
      }
      else if(tree.z > 10000 - fl)
      {
      tree.z -= 10000;
      }
      var scale:Number = fl / (fl + tree.z);
      tree._xscale = tree._yscale=scale*100;
      tree._x = vpX + tree.x * scale;
      tree._y = vpY + tree.y * scale;
      tree._alpha = scale * 60 + 40;
      tree.swapDepths(-tree.z);
      }
      }