-
if(i>$){i=:);}
please clean up line for me
Hey there!
Im building a tween prototype and it works great, but the argument with the delete onEnterFrame is a bit sloppy. How can I write it using the var i in the for loop?
Cheers!
code:
MovieClip.prototype.tween = function(prop, finalValue, tweenSpeed) {
var prop:Array;
var finalVal:Array;
var tweenSpeed:Number;
var finished:Number;
if (tweenSpeed == undefined) {
tweenSpeed = .09;
}
this.onEnterFrame = function() {
for (var i = 0; i<=(prop.length-1); i++) {
//easeOut
this[prop[i]] += (finalValue[i]-this[prop[i]])*tweenSpeed;
//easeOutElastic
if (parseInt(this[prop[i]]) == parseInt(finalValue[i])) {
delete finalValue[i];
if (finalValue[0] == undefined && finalValue[1] == undefined && finalValue[2] == undefined && finalValue[3] == undefined && finalValue[4] == undefined && finalValue[5] == undefined && finalValue[6] == undefined && finalValue[7]) {
delete this.onEnterFrame;
}
}
trace(this[prop[i]]+" / "+finalValue[i]);
}
};
};
//
onMouseDown = function () {
box.tween(["_xscale", "_yscale"], [400, 500], .09);
};
-
You could use the splice command for arrays. If it has reached its final value you could remove it from the array. Then check the length of the array!. If it is empty the script will delete the onEnterFrame:
Code:
MovieClip.prototype.tween = function(prop, finalValue, tweenSpeed) {
var prop:Array;
var finalVal:Array;
var tweenSpeed:Number;
var finished:Number;
if (tweenSpeed == undefined) {
tweenSpeed = .09;
}
this.onEnterFrame = function() {
for (var i = 0; i<=(prop.length-1); i++) {
//easeOut
this[prop[i]] += (finalValue[i]-this[prop[i]])*tweenSpeed;
//easeOutElastic
if (parseInt(this[prop[i]]) == parseInt(finalValue[i])) {
finalValue.splice(i,1);
}
trace(this[prop[i]]+" / "+finalValue[i]);
}
if(finalValue.length == 0){
delete this.onEnterFrame
}
};
};
Edit: Sorry, I put the third if condition in the wrong line. This code should work now.
Last edited by andreaskrenmair; 09-06-2005 at 12:28 PM.
-
if(i>$){i=:);}
Yeah, great idea. works like a charm.(once I put the length argument in the this.onEnterframe )
Thanks
Last edited by falshdancer; 09-06-2005 at 11:39 AM.
la la la la laaaaaaa
-
Flashkit Veteran
try this dude, btw what is up haven't seen you forever:
PHP Code:
for(i=0;i<=(prop.length-1);i++) {
if(finalValue[i] == undefined) {
if(i==(prop.length-1)) {
delete this.onEnterFrame
}else{
continue;
}
}else{
break;
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|