# AS2 to AS3

**URL:** https://forum.kirupa.com/t/as2-to-as3/271786
**Category:** Uncategorized
**Created:** [September 28, 2008, 3:18pm UTC](https://forum.kirupa.com/t/as2-to-as3/271786 "2008-09-28T15:18:25Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![renton79](https://avatars.discourse-cdn.com/v4/letter/r/97f17d/32.png) [@renton79](https://forum.kirupa.com/u/renton79)
#### Post date: [September 28, 2008, 3:18pm UTC](https://forum.kirupa.com/t/as2-to-as3/271786/1 "2008-09-28T15:18:25Z")

</div>

Hi I found this code on [[COLOR=#0066cc]www.cleverpig.com[/COLOR]](http://www.cleverpig.com/) and it is exactly what I need. But I have problems with converting it to AS3.  
Especialy I have problem with last part in for loop.  
Can anyone help me with it please?

```auto

// script and comments by CleverPig ([www.cleverpig.com](http://www.cleverpig.com))
//expects a 600x300 stage with a dark background colour
//
// depth of the picture plane...
_global.ppDist = 500;
_global.speed = 5;
//update function to handle perspective projection and scaling
update = function ()
{
 perspective = ppDist / (ppDist - this.z);
 this._x = this.x * perspective;
 this._y = this.y * perspective;
 this._xscale = this._yscale = 100 * perspective;
 // add z motion...
 this.z += speed;
 // push back when it reaches the view position...
 if (this.z > 490)
 {
  this.z -= 2000;
 }
}
//empty clips for drawing...
_root.createEmptyMovieClip ("drawing", 1);
_root.drawing.createEmptyMovieClip ("sq", 1);
// centre the 'drawing' mc on the stage...
_root.drawing._x = 300;
_root.drawing._y = 150;
// draw a solid white 4x4 square in the 'sq' mc
_root.drawing.sq.beginFill (0xffffff, 100);
_root.drawing.sq.moveTo (-2, -2);
_root.drawing.sq.lineTo (2, -2);
_root.drawing.sq.lineTo (2, 2);
_root.drawing.sq.lineTo (-2, 2);
_root.drawing.sq.lineTo (-2, -2);
_root.drawing.sq.endFill ();
// hide the original 'sq' off stage
_root.drawing.sq._y = 1000;
// make 198 copies of the square
for (i = 2; i < 400; i++)
{
 initOb = {x:random (600) - 300, y:random (300) - 150, z:random (2000) - 1600};
 //note: random(600)-300 gives a random integer between -300 & 299
 //note: random(2000)-1600 gives a random integer between -1200 & 399
 _root.drawing.sq.duplicateMovieClip ("s" + i, i, initOb);
 _root.drawing["s" + i].onEnterFrame = _root.update;
}

```
