PDA

View Full Version : AS2 to AS3 example


Incrue
02-16-2006, 09:58 AM
So, how this code would be in AS3???
Please help me to understand, i can only understand with examples...
origin = new Object();
origin.x = 150;
origin.y = 150;

focalLength = 300;

figureA.x = -50;
figureA.y = 0;
figureA.z = 0;
figureA.dir = 1;

figureB.x = 0;
figureB.y = 0;
figureB.z = 250;
figureB.dir = 1;

figureC.x = 50;
figureC.y = 0;
figureC.z = 500;
figureC.dir = 1;

speed = 20;
backAndForth = function(){
this.z += speed*this.dir;
if (this.z > 500){
this.z = 500;
this.dir = -1;
}else if (this.z < 0){
this.z = 0;
this.dir = 1;
}

var scaleRatio = focalLength/(focalLength + this.z);
this._x = origin.x + this.x * scaleRatio;
this._y = origin.y + this.y * scaleRatio;
this._xscale = this._yscale = 100 * scaleRatio;
this.swapDepths(-this.z);
};
figureA.onEnterFrame = backAndForth;
figureB.onEnterFrame = backAndForth;
figureC.onEnterFrame = backAndForth;

hangalot
02-16-2006, 04:17 PM
this is a very AS1 type example. you would be able to do this in as3, in a simmiliar way to which you have there, but because you are dynamically accessing and creating functions it will be slower than doing it the right way in AS3

there are a ton of blogs about that have examples of AS3 applications.