PDA

View Full Version : AS2 to AS3 conversion


Jeremy78
04-23-2008, 02:59 PM
I was wondering if someone could maybe help convert this into AS3. I've posted this before a while back but no one responded. I've considered using !== logical negation instead of using <> but that didn't get me far. Im still missing the concept of setting up the functions and variables for AS3. ANY help would be most appreciated.


function bgmove(){
bg_mc.onEnterFrame=function(){
if(this._x<>Math.round(xpos[pos])&&this._y<>Math.round(ypos[pos])&&this._xscale<>Math.round(wpos[pos])&&this._yscale<>Math.round(hpos[pos])){
this._x+=Math.round((xpos[pos]-this._x))/deceleration;
this._y+=Math.round((ypos[pos]-this._y))/deceleration;
this._xscale+=Math.round((wpos[pos]-this._xscale))/deceleration;
this._yscale+=Math.round((hpos[pos]-this._yscale))/deceleration;
this._rotation+=Math.round((rpos[pos]-this._rotation))/5;
}else{
this.onEnterFrame=null;
}
}
bg2_mc.onEnterFrame=function(){
if(this._x<>Math.round(xpos[pos])&&this._y<>Math.round(ypos[pos])&&this._xscale<>Math.round(wpos[pos])&&this._yscale<>Math.round(hpos[pos])){
this._x+=Math.round((xpos[pos]-this._x))/15;
this._y+=Math.round((ypos[pos]-this._y))/15;
this._xscale+=Math.round((wpos[pos]-this._xscale))/15;
this._yscale+=Math.round((hpos[pos]-this._yscale))/15;
this._rotation+=Math.round((rpos[pos]-this._rotation))/5;
}else{
this.onEnterFrame=null;
}
}
}

nikefido
04-23-2008, 04:23 PM
hopefully this will get you started:


bg_mc.addEventListener(Event.ENTER_FRAME, onEnter);

function onEnter(e:Event):void {
if(event.Target.x<>Math.round(xpos[pos])&&event.Target.y<>Math.round(ypos[pos])&&event.target.scaleX<>Math.round(wpos[pos])&&event.target.scaleY<>Math.round(hpos[pos])){
this._x+=Math.round((xpos[pos]-this._x))/deceleration;
this._y+=Math.round((ypos[pos]-this._y))/deceleration;
this._xscale+=Math.round((wpos[pos]-this._xscale))/deceleration;
this._yscale+=Math.round((hpos[pos]-this._yscale))/deceleration;
this._rotation+=Math.round((rpos[pos]-this._rotation))/5;
}else{
event.target.removeEventListener(Event.ENTER_FRAME );
}
}


I didn't finish all the changes:
What you need to do is change all instances of "this" and change it to "event.Target".

All _x, _y, _rotation are not referred to without the "_" (.x, .y. .rotation).

Scale is no longer 0-100, but rather 0-1, so some math might be off somewhere because of that.

use the remove enter frame to remove that listener.

Jeremy78
04-23-2008, 04:34 PM
thanks bro, I'll give it a try