A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: please clean up line for me

  1. #1
    if(i>$){i=:);} falshdancer's Avatar
    Join Date
    Nov 2003
    Location
    NYC
    Posts
    546

    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);
    };

    la la la la laaaaaaa

  2. #2
    Senior Member
    Join Date
    May 2003
    Location
    Austria
    Posts
    146
    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.

  3. #3
    if(i>$){i=:);} falshdancer's Avatar
    Join Date
    Nov 2003
    Location
    NYC
    Posts
    546
    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

  4. #4
    Flashkit Veteran joejoe2288's Avatar
    Join Date
    Apr 2004
    Location
    Hickville, Oregon
    Posts
    2,554
    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;
    }

    So tired of all the fighting....

    http://joejoe2288.kawanda.net

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center