Menu that Swings In - Step Seven: ActionScript for the Timeline
Posted by : PhilS on Jul 31, 2008
The following Actionscript will make the first button move. There is additional code that makes the other buttons follow the first button, a bit like follow the leader.
1. To avoid errors lock the Buttons Layer:
2. Click on the Insert Layer button:
3. Rename the new Layer to: Actions
4. Place the following ActionScript on Frame 1 in the: Actions Layer
// stops the movie on frame 1
stop();
// sets the x position for the menu to stop and go back to. You may need to
adjust these two settings
var goto = 30;
var backto = -80;
// declares a variable called go which will be used to help create the
movement
var go = 0;
// sets the speed - don't set it too slow
setInterval(mousePosition, 5);
//this function is called by the word 'mousePosition' in the setInterval above
function mousePosition() {
// sets the x position for the mouse to activate the menu movement
if (_xmouse<=20) { //adjust number as necessary
MC1._x = MC1._x+bounce("right");
}
if (_xmouse>=110) { //adjust number as necessary
MC1._x = MC1._x-bounce("left");
}
}
// this function is called by 'bounce' in the mousePosition function above
function bounce(leftOrRight) {
// sets the swing properties
if (leftOrRight == "right") {
go = (goto-MC1._x);
go *= .09;
}
if (leftOrRight == "left") {
go -= (backto-MC1._x);
go *= .09;
}
return go;
}
5. Test Your Movie: Control - Test Movie (Ctrl + Enter)
6. Place the Mouse over the: Menu bar

So far only the first Button works.
Note: Only one Button will work. To make the rest of the Buttons work there one more step.
7. Close the Test Window:

no comment
Add comment