# AS2 to AS3

**URL:** https://forum.kirupa.com/t/as2-to-as3/265954
**Category:** Uncategorized
**Created:** [July 14, 2008, 10:02pm UTC](https://forum.kirupa.com/t/as2-to-as3/265954 "2008-07-14T22:02:25Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![tbear](https://avatars.discourse-cdn.com/v4/letter/t/c77e96/32.png) [@tbear](https://forum.kirupa.com/u/tbear)
#### Post date: [July 14, 2008, 10:02pm UTC](https://forum.kirupa.com/t/as2-to-as3/265954/1 "2008-07-14T22:02:25Z")

</div>

Hi,  
Im trying to update this AS2 code (sparkle animation) to AS3  
I cant seem to get it working at all (im not up to date on how to make this work in AS3)

Please help…:stare: Here is the code.  
There are two different codes

1…

i = 2;  
while (Number(i)\<50) {  
duplicateMovieClip(“t1”, “t” + i, i);  
setProperty(“t” + i, \_rotation, random(360));  
scalefactor = 40+Number(random(60));  
setProperty(“t” + i, \_xscale, scalefactor);  
setProperty(“t” + i, \_yscale, scalefactor);  
tellTarget (“t” + i) {  
gotoAndPlay(random(5));  
}  
i = Number(i)+1;  
}

2…  
//make the target “bug” invisible  
spark.sparkcenter.\_visible = false;

//s  
var n:Number = 1;  
var lifetime:Number =40;  
var eratic:Number = 300;

var particleID:Number = setInterval(startParticle, 1);

function startParticle():Void  
{  
insertParticle(spark.\_x, spark.\_y);  
}

function insertParticle(x:Number, y:Number):Void  
{  
var mc:MovieClip = attachMovie(“particle”, “particle” + n, n, {\_x:x,\_y:y});  
mc.\_visible = true;  
// Initialize X and Y velocities  
mc.vx = (random(5) - 1);  
mc.vy = (random(5) - 1);  
// Set number of loops particle will live  
mc.life = lifetime;  
mc.onEnterFrame = function() {  
// Get current position and add XYVelocities  
this.curx = this.\_x;  
this.cury = this.\_y;  
this.\_x += this.vx;  
this.\_y += this.vy;  
// Alpha and scale is dependent on proximity to death  
this.ap = (this.life / lifetime) \* 100;  
this.\_alpha = this.ap;  
this.\_xscale = this.ap;  
this.\_yscale = this.ap;  
// Eratic behavior closer to death  
this.vx += (random(eratic) - (eratic / 2)) / this.ap;  
this.vy += (random(eratic) - (eratic / 2)) / this.ap;  
// Reduce particle life  
this.life–;  
if (this.life \< 0) {  
// Life counter is up, remove particle  
delete this.onEnterFrame;  
removeParticle(this);  
}  
};  
n++;  
}

function removeParticle(mc:MovieClip):Void  
{  
mc.removeMovieClip();  
}

---

<div class="post-metadata">

### Author: ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)
#### Post date: [July 14, 2008, 10:10pm UTC](https://forum.kirupa.com/t/as2-to-as3/265954/2 "2008-07-14T22:10:03Z")

</div>

Have you seen the AS2 to AS3 migration page?: [http://livedocs.adobe.com/flex/3/langref/migration.html](http://livedocs.adobe.com/flex/3/langref/migration.html)  
The AS3 Tip of the Day thread?: [http://www.kirupa.com/forum/showthread.php?t=223798](http://www.kirupa.com/forum/showthread.php?t=223798)

You posted quite a bit of code… so it would probably be better for you to read the information in the above links and learn how to convert it yourself.
