Object move wgen clicking a button

Hello,

I have a menu and I want a MC to move from button to button when these buttons are clicked. How to do that?

Thanks,
Sven

the easiest way to do this is with an ease.

Lets assume you have a vertical menu. All your menu items are listed one after the other ina column. So when you click on any one of these items (buttons) a movieclip should move to that position.

Basically the process is this. Set up a continuous event (enterFrame) to run your moving movieclip and have it move towards a specified ‘target’ position. This position will be defaulted at lets say the first item in the menu. as where the clip is placed to start (essentially not moving at all since its already at its target location). then whenever you press a button, you alter that target of the movieclip to be the location of that button. Then the enterframe event will, everyframe, position the movieclip closer and closer to that target position until reaching it.

So heres some code


// on the moving movieclip, Ill give it the instance name "box":
onClipEvent(load){
	target_y = _y
	ease = 4
}
onClipEvent(enterFrame){
	_y += (target_y - _y)/ease
}

where target_y is the target location of the clip and the ease is the ease speed factor (you can play around with this to see how the movement reacts). Now all we need to do is change the target_y of this ‘box’ with the buttons in the menu. For each button just include something like


on(press){
	box.target_y = 100;
	// other onPress actions...
}

where 100 is the desired _y position of box. This can be on the button itself or even offset from it if you want.

if using MX, you can use the _y loc of the button iteself to make it easier on yourself


buttonName.onPress = function(){
	box.target_y = this._y
	// other onPress actions...
}