Movement code

i put this code into a button…

on (release) {
	if (_root.menu._x != 298.7) {
		speed = 1;
		_root.menu._x += speed;
    } else {
		stop();
	}
}

but it only increments its _x by 1 when i repeatedly click it… shouldn’t it continue to run through the loop?

or do i need a for loop?

You have it on an on release which means that it runs through the code once with each click. So yes you need a for loop or maybe try one of the easing equations out there?

:hr:

I did something similar, but for a movieclip. Put this code into a movieclip, and tell me if that is something like you want.

onClipEvent (load) {
	_x = 18;
	div = 5;
}
onClipEvent (enterFrame) {
	_x += (endX-_x)/div;
	_root.link_mc.onPress = function() {
		endX = 40;
	};
	_root.link_mc.onRelease = function() {
		endX = 18;
	};
}

i didnt even bother, there were too many errors in it when flash tried to do that… anyway, can someone tell me how to do a for loop to make that work?
i tried:


on (release) {
     for (_root.menu._x != 298.7; _root.menu._x != 298.7; ) {
		speed = 3;
	    _root.menu._x += speed;
     }
}

but that came up with something about it being too processor intensive that it will hang my system

im confused… btw lunatic, those scripts didnt work… when i clicked it, nothing happened… and i put the first script on a separate actions layer in frame one, and then i put the second on the button…

Let’s say your button’s instance name is ‘but’, put this in the main timeline

speed = 3 ;

but.onRelease = function () {
     _root.menu.move () ;
} ;

function move () {
     this.onEnterFrame = function () {
          this._x += speed ;
          if (this._x < 300 && this._x > 295) delete this.onEnterFrame ;
     } ;
} ;

put this in the main timeline

like, on a separate actions layer in frame one?

Yes.

still didnt work, :-/ check it out… (I couldnt attach the FLA it was about 700 kb too big :moustache )

K here is the .fla:

http://www.graphicslash.com/mathprojectworking.fla

I implemented the code you guys have been talking about in this thread…it’s in the first frame, GS.

http://digitalink-designs.com/gs.zip

Adam

heey thanks adam, i wonder what i did wrong :frowning:

My mistake.

speed = 3 ;

but.onRelease = function () {
     _root.menu.move () ;
} ;

MovieClip.prototype.move = function () {
     this.onEnterFrame = function () {
          this._x += speed ;
          if (this._x < 300 && this._x > 295) delete this.onEnterFrame ;
     } ;
} ;

Is this working any better?

yes thanks :slight_smile: