3 Replies Latest reply on Nov 22, 2009 10:47 AM by kglad

    AS2 to AS3 Conversion

    benoismyname

      Hi;

      I think I get how to convert most of an old script. But one line is throwing me for loops:

       

      var _tempClip2 = _root.attachMovie("explosion2", "explosion2_" + _root.getNextHighestDepth(), _root.getNextHighestDepth());

       

      The above is the first line where explosion2_ is mentioned. I've thought up this:

       

      var explosion2:MovieClip = new MovieClip();
      var explosion2_:MovieClip = new explosion2();
      this.addChild(explosion2_)

       

      but this code doesn't mention _tempClip2

      Here is the complete AS2 code:

       

      var explosionParticleAmount:Number = 15;
      var explosionDistance:Number = 30;
      var explosionSize:Number = 100;
      var explosionAlpha:Number = 75;

       

      function addExplosion(_targetX:Number, _targetY:Number, _explosionParticleAmount:Number, _distance:Number, _explosionSize:Number, _explosionAlpha:Number):Void
      {
          //run a for loop based on the amount of explosion particles
          for(var i = 0; i < _explosionParticleAmount; i++)
          {
              //create particle
              var _tempClip2 = _root.attachMovie("explosion2", "explosion2_" + _root.getNextHighestDepth(), _root.getNextHighestDepth());
              var _tempClip = _root.attachMovie("explosion", "explosion" + _root.getNextHighestDepth(), _root.getNextHighestDepth());
              //set particle position
              _tempClip._x = _targetX+random(_distance)-(_distance/2);
              _tempClip._y = _targetY+random(_distance)-(_distance/2);       
              _tempClip2._x = _targetX+random(_distance)-(_distance/2);
              _tempClip2._y = _targetY+random(_distance)-(_distance/2);

       

              //get random particle scale
              var tempRandomSize = random(_explosionSize)+_explosionSize/2;
              //set particle scale
              _tempClip._xscale = tempRandomSize;
              _tempClip._yscale = tempRandomSize;
              //get random particle scale
              var tempRandomSize = random(_explosionSize)+_explosionSize/2;
              //set particle scale
              _tempClip2._xscale = tempRandomSize;
              _tempClip2._yscale = tempRandomSize;
             
              //set particle rotation
              _tempClip2._rotation = random(359);
             
              //set particle alpha
              _tempClip._alpha = random(explosionAlpha)+explosionAlpha/4;
              _tempClip2._alpha = random(explosionAlpha)+explosionAlpha/4;
          }
      }

       

      /**
      *
      * Mouse Controls
      *
      */
      //create an object that we'll listen to
      mouseListener = new Object();

       

      //on Click, create explosionle
      mouseListener.onMouseDown = function()
      {   
          addExplosion(_xmouse, _ymouse, explosionParticleAmount, explosionDistance, explosionSize, explosionAlpha);
      };

       

      //add listener
      Mouse.addListener(mouseListener);

       

      Please advise.

      TIA,

      beno