Below is AS2 attempt to convert to AS3. The comment sections have the AS2, while I have tried to change to AS3. I am picking up the skill after a few years. I wanted to share this code to verify what I am doing is correct. If not, what can I do differently? Not too good on the math side of things so it becomes intimidating sometimes. Does the ENTER_FRAME need to be specified somehow? Any assistance and advice would be great!
This project is a flash website written in AS2. I started learning AS3 when CS5 came out. I don't mind doing the parts that looks repeated. Please verify the code is correct.
import flash.display.Loader;
//Calculates the amount to load and how much is loaded
/*AS2.0 script:
percentLoaded = Math.round(root.getBytesLoaded() / root.getBytesTotal() * 100);*/
var percentloaded:Number = load/total * 100;
var myWidth:Number = this.loaderInfo.bytesTotal;
var myMove:Number = this.loaderInfo.bytesLoaded;
//Sets the width of the bar
/*AS2.0 script:
this.myWidth(this.loadBar, percentLoaded * 2);
this.myMove(this.mc_loadNum, percentLoaded * 2 );
loadNum.text = percentLoaded +"%";
*/
percentLoaded = loadBar(percentage*100);
LoadBar.Scalex = percentage;
var loadBar: Number = percentLoaded *2;
var mc_loadNum:Number = percentLoaded * 2;
var loadNum.text = percentLoaded + "%";`
// FUNCTIONS
/*AS2.0 Scripts:
function myWidth(moveObj, newWidth) {
moveObj.w = moveObj._width;
moveObj.dwidth = newWidth-moveObj.w;
moveObj.t = 0;
NFRAMES = 6; "<-- number of stops(); placed on frames"
moveObj.onEnterFrame = function() {
if (moveObj.t++<NFRAMES) {
moveObj._width = easeOutQuad(moveObj.t, moveObj.w, moveObj.dwidth,
NFRAMES);
} else {
delete this.onEnterFrame;
}
};
}
function myMove(moveObj, newX) {
moveObj.x = moveObj._x;
moveObj.dx = newX-moveObj.x;
moveObj.t = 0;
NFRAMES = 6;
moveObj.onEnterFrame = function() {
if (moveObj.t++<NFRAMES) {
moveObj._x = easeOutQuad(moveObj.t, moveObj.x, moveObj.dx, NFRAMES);
} else {
delete this.onEnterFrame;
}
};
}
easeOutQuad = function (time, beginX, changeX, durationX) {
if ((time /= durationX/2)<1) {
return changeX/2*time*time+beginX;
}
return -changeX/2*((--time)*(time-2)-1)+beginX;
};
//FRAME2 | ACTIONS
if (percentLoaded < 100 ) {
gotoAndPlay("loading");
}
//FRAME3 | ACTIONS
root.gotoAndPlay(48);
*/
LoadBackground.addEventListener(Event.ENTER_FRAME, moveObj);
function moveObj(moveObj, newWidth) {
var moveObj.w = moveObj.width;
var moveObj.dwidth = newWidth - moveObj.w;
var moveObj.t: Number = 0;
var NFRAMES: Number = 6;
moveObj.onEnterFrame = function () {
if (moveObj.t++ < NFRAMES) {
moveObj._width = easeOutQuad(moveObj.t, moveObj.w, moveObj.dwidth, NFRAMES);
} else {
delete this.onEnterFrame;
}
};
}
x.addEventListenter(Event.ENTER_FRAME, myMove);
function myMove(Event.moveObj, newX) {
moveObj.x = moveObj.x;
moveObj.dx = newX - moveObj.x;
moveObj.t = 0;
NFRAMES = 6;
moveObj.onEnterFrame = function () {
if (moveObj.t++ <= NFRAMES) {
moveObj.x = easeOutQuad(moveObj.t, moveObj.x, moveObj.dx, NFRAMES);
} else {
delete this.onEnterFrame;
}
};
}
function easeOutQuad(time, beginX, changeX, durationX) {
if ((time /= durationX / 2) < 1) {
return changeX / 2 * time * time + beginX;
}
return -changeX / 2 * ((--time) * (time - 2) - 1) + beginX;
}
/*
easeOutQuad = function (time, beginX, changeX, durationX) {
if ((time /= durationX / 2) < 1) {
return changeX / 2 * time * time + beginX;
}
return -changeX / 2 * ((--time) * (time - 2) - 1) + beginX;
};
*/