AS2 to AS3 migration - several Questions

i am graphics designer & also programming php. I stopped working with flash as flash Player 5 or 6 came out, and now that i started to do flash again Actionscript is giving me a headache. I am trying to get through the Actionscript Essentials Book but i need to experiment on the side to understand it - or probably just to keep my mind sane…

Now i found a nice script in AS2 which i try to migrate to AS3 without much success. I managed to change the random() & define the variables… but still many questions:

  • mc._x or mc._alpha become mc.x and mc.alpha?
  • _xmouse+1 now gets mouseX+1?
  • var o = this.attachMovie(“part”, “p”+i, i); gives me error 1060: attachMovie is no longer supported. But the solution goes over my head. How do i need to implement that?

i have attached the samplecode if someone wants to take a look. and i hope the question wasn’t too stupid :slight_smile:


     [LEFT]var n = 15;
var vf = 3; //Stir factor
var af = 0.9; //Air fric
var bf = 0.1; //Bounce
var ks = 0.0; //Spring
var g = 0.0 //Gravity

var sw = 1000;
var sh = 500;
for(var i=0;i<n;i++){
    var o = this.attachMovie("part", "p"+i, i);
    o._x = Math.random()*400;
    o._y = Math.random()*150;
    o._alpha = Math.random()*200;
    var xscale= Math.random()*100;
    var yscale= xscale+Math.random()*20;
    o._yscale = yscale;
    o._xscale = xscale;
    o._rotation = Math.random()*360;
    o.x0 = o._x;
    o.y0 = o._y;
    o.vx = 0;
    o.vy = 0;
}
var mpx = mouseX+Math.random()*1;
var mpy = mouseY+Math.random()*1;
this.onMouseMove = function(){
    var dx = mouseX - mpx;
    var dy = mouseY - mpy;
    for(i=0;i<n;i++){
        o = this["p"+i];
        var ox = mouseX - o._x;
        var oy = mouseY - o._y;
        var oa = Math.sqrt(ox*ox+oy*oy);
        if(oa != 0){
            o.vx += dx*vf/oa;
            o.vy += dy*vf/oa;
        }
    }
    mpx = mouseX;
    mpy = mouseY;
}
this.onEnterFrame = function(){
    for(i=0;i<n;i++){
        o = this["p"+i];
        o.vx -= (o._x - o.x0)*ks;
        o.vy -= (o._y - o.y0)*ks;
        
        o.vx *= af;
        o.vy *= af;
        o.vy += g;
        o._x += o.vx;
        o._y += o.vy;
        if(o._x>sw){
            o.vx *= -bf;
            o._x = sw;
        }
        if(o._y>sh){
            o.vy *= -bf;
            o._y = sh;
        }
        if(o._x<0){
            o.vx *= -bf;
            o._x = 0;
        }
        if(o._y<0){
            o.vy *= -bf;
            o._y = 0;
        }
    }
}[/LEFT]
 

thx
kami