theEclipse
Programmer
Hello
I am breaking into the flash coding realm and am finding some difficulty with writing repetitive code....I would like to find a way to streamline this code so it is not so repetitive.
I need to expand it to account for x and y positioning too, and so I'll need to add two more sections that are exactly the same as the above chunks, with the exception of the data that is changing.
To me, this repetitive code screams 'loop over an array' or 'object orient me' but I cannot seem to figure out how I can accomplish it. If I could pass primitives by reference, I could do it easy enough...but AS3 only passes primitives by value.
Any ideas?
Robert Carpenter
Remember....eternity is much longer than this ~80 years we will spend roaming this earth.
ô¿ô
I am breaking into the flash coding realm and am finding some difficulty with writing repetitive code....I would like to find a way to streamline this code so it is not so repetitive.
Code:
function update(){
if (!needsUpdate) return;
needsUpdate = false;
var tHeight, tWidth, tAlpha;
if (big) {
tHeight = bigHeight;
tWidth = bigWidth;
tAlpha = bigAlpha;
} else {
tHeight = smallHeight;
tWidth = smallWidth;
tAlpha = smallAlpha;
}
if (tHeight != this.height){
if (Math.abs(tHeight - this.height) < 5){
this.height = tHeight;
} else {
this.height += (tHeight - this.height) * .1;
}
needsUpdate = true;
}
if (tWidth != this.width){
if (Math.abs(tWidth - this.width) < 5){
this.width = tWidth;
} else {
this.width += (tWidth - this.width) * .1;
}
needsUpdate = true;
}
if (tAlpha != this.alpha){
if (Math.abs(tAlpha - this.alpha) < 0.5){
this.alpha = tAlpha;
} else {
this.alpha += (tAlpha - this.alpha) * .1;
}
needsUpdate = true;
}
if (needsUpdate) {
setTimeout(update,10);
}
}
I need to expand it to account for x and y positioning too, and so I'll need to add two more sections that are exactly the same as the above chunks, with the exception of the data that is changing.
To me, this repetitive code screams 'loop over an array' or 'object orient me' but I cannot seem to figure out how I can accomplish it. If I could pass primitives by reference, I could do it easy enough...but AS3 only passes primitives by value.
Any ideas?
Robert Carpenter
Remember....eternity is much longer than this ~80 years we will spend roaming this earth.
ô¿ô