dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [RESOLVED] [F8] Is there anyway to "lock" a variable?

  1. #1
    yeah yeah yeah sandyrivers's Avatar
    Join Date
    Jul 2002
    Location
    Jibblies!
    Posts
    480

    resolved [RESOLVED] [F8] Is there anyway to "lock" a variable?

    I don't know why this is escaping me, but I'm banging my head on this one.

    What I want to do is tween a movie clip from point a to point b on the y axis if a button is pressed. I understand the mechanics of coding what I want to do but I don't want to be bothered with plugging in the actual _y starting and ending points. I want to use a variable.

    code:

    var myMCnewY = myMC._y + 103;
    mcTween = function() {
    this.onEnterFrame = function() {
    if (myMC._y < myMCnewY){
    myMC._y +=10;
    } else {
    myMC._y = myMCnewY
    delete this.onEnterFrame();
    }
    }
    }
    buttonMC.onRelease = function () {
    mcTween();
    }



    The obvious problem with this is that since the myMCnewY variable contains myMC._y, it'll always be greater than the clip's current position and the tween will never end. How do I "capture" the ending point in a variable, and then "lock" that number so that it doesn't increase due to the onEnterFrame?

    Also, I rather not use the Tween class, as it wasn't working all that well for me and I understand this way.

    Thanks in advance for any help!

    -Sandy
    Last edited by sandyrivers; 02-09-2009 at 12:26 PM.
    Sigs R4 Suckers! Wait... I mean.... nevermind...

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    ???
    Code:
    //
    mcTween = function (mc, newY) {
    	this.onEnterFrame = function() {
    		if (mc._y < newY) {
    			mc._y += 10;
    		} else {
    			mc._y = newY;
    			delete this.onEnterFrame;
    		}
    	};
    };
    //
    buttonMC.onRelease = function() {
    	mcTween(myMC, myMC._y + 103);
    };

  3. #3
    yeah yeah yeah sandyrivers's Avatar
    Join Date
    Jul 2002
    Location
    Jibblies!
    Posts
    480
    you are awesome. thank you.

    I can never remember what goes in the parenthesis when writing a function to make it work like I want. I always leave it blank and try to figure out a way around it.

    anyways... thanks!
    Sigs R4 Suckers! Wait... I mean.... nevermind...

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