The aim of the tutorial is to learn how to create a menu with swings in and out. When your mouse goes over the gray menu bar to the left, the menu swings into view. You can then click on the Flash menu buttons. When you move your mouse away from the buttons in the menu swings away.
Step one: Setting up the Document
This movie works by tracking the position of the mouse. If the mouse is not visible to the Flash Movie when your web page first loads, the menu buttons may be visible. The mouse may not be visible to Flash because it is over the address line of the browser or elsewhere. Once the shock wave has locked onto the mouse (the mouse cursor has moved over the movie) this problem will not occur even if the mouse moves out of the movie and onto the browser.
- Go to Modify > Document
- Set up a small movie. Mine is: 525 x 200 pixels
- If you wish select a: Background Colour
- Click: OK
Step two: The Invisible Button
- Go to: Insert > New Symbol
- Name it: Invisible Button
- For Behaviour select: Button
- Click: OK
- In the frame below the word HIT, right click (Mac: Ctrl click) and select: Insert Blank Keyframe
- Using the Rectangle Tool
draw
a: Rectangle - Place the rectangle on top of the cross in the: Centre of Stage
- Return to the Main Stage by clicking on the Scene 1 button:

- Open your Library: Window>Library (F11)
- Rename Layer 1: Buttons
- Drag onto the Main Stage the new button: Invisible Button
- With the Free Transformation Tool
resize
the button so that it covers the: Entire Stage
The Invisible Button now covers the entire Stage.
- Attach the following Actionscript to the button:
on (rollOver) {
gotoAndStop(2);
}
Because it is a Roll Over button, as soon as the mouse goes over top of the movie, the Play Head will move to frame 2 and stop. The reason for the Invisible Button is to give Flash an opportunity to find the location of the Mouse Cursor.
Note: It does not matter how big the rectangle is.
Step three: Create the Menu Image
- In the Timeline click on the Insert Layer button:

- Rename the new Layer to: Menu
- Using the rectangle tool
on
the left off the Stage draw a long: Rectangle - With the Text Tool type: Menu
- With the Free Transformation Tool
: Turn
the Text
Note: At present the Movie only has one frame but latter we will additional frames to the Movie. To ensure that the Menu Image is visible throughout the Movie you will need to come back to this layer and add additional frames. I will remind you of this at the end of the tutorial.
Step four: Creating the Graphics
- Create a new Layer and call it: Graphics
- Place any graphics or text that you may want:
- In Frame 10 of the Graphics Layer, right
click and select: Insert Blank KeyFrame
Your Layers should look like this.
Note: Technically the new Keyframe does not need to be on frame 10 but could be on the next unused frame, which is frame 3. I have selected to use frame 10 so that Button 1 will match frame 10 and Button 2 will match frame 20 etc. The reason I have done this is because frame 1 is occupied with the invisible button so my real Button 1 cannot match frame 1.
- Place any graphics or text you want:
- Repeat five times what you have just done with different graphics for
frame 20, frame 30, frame 40 etc.
Step five: Create Buttons
- Go to: Insert > New Symbol
- Name it: Button 1
- For Behaviour select: Button
- Click: OK
- Draw a small: Rectangle
- Type text on it: button 1
Note: Make sure your text and your rectangle are different colours!!
Cross Ref: If you do not know how to create buttons see the tutorial: Creating Buttons
- Return to the Main Stage by clicking on the Scene 1 button:
- Repeat what you have done to create: Button 2 through to Button
6
Note: My Button 6 returns the user back to the starting point so I have typed Home as the Label.
My six buttons.
- When you have finished your Buttons go back to the Main Stage by clicking
on the Scene 1 Tab:
Note: Do not place your buttons on the Main Stage.
Step six: Adding the Menu
- Create a new symbol called: Menu 1 MC
- The behaviour should be: Movie Clip
- Open your Library and drag Button 1 into the new Symbol: Menu
1 MC
My Menu 1 MC.
- When you have finished your Menu 1 MC go back to the
main stage by clicking on the Scene 1 Tab:

- To create other menu Items: Repeat Step 1 to Step 5
Note: All your symbols are still in the Library, none of them have yet been placed on the Main Stage.
All the Symbols in my Library.
Step seven: Placing the Menu
- When you have finished go back to the Main Stage.
- Right click on Frame 2 of the layer: Buttons
- Select Insert > Blank Keyframe
- Place all your Menu Movie Clip buttons just off the left hand side of the
stage.
- If the Property Inspector is closed, open it: Window > Properties (Ctrl F3)
- Select the first Movie Clip and give it an Instance Name of: MC1
Note: Do not type a space between the MC and the 1. It must be one word: MC1
The Instance Name for:MC1
- Give as Instance Name the next button: MC2
- Give instance names to the rest of the buttons: MC3 etc.
Step eight: ActionScript for the Timeline
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.
- Create a new layer called: Actions
- Place the following actionscript on Frame 1 in the: Actions
Layer
// stops the movie so that the roll over button moves the user to frame 2
stop();// sets the x position for the menu to stop at and go back to
goto = 30;
backto = -80;// sets the speed - don't set it too slow
setInterval(mousePosition, 5);// this function is called by the word 'mousePosition' in the setInterval above
// this function is called by 'bounce' in the mousePosition function above
function mousePosition() {
// sets the x position for the mouse to activate the menu movement
if (_xmouse<=20) {
MC1._x = MC1._x+bounce("right");
}
if (_xmouse>=110) {
MC1._x = MC1._x-bounce("left");
}
}
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;
}
If you are using Flash MX your menu should now happily swing back and forth depending on the mouse position.
Important Note If you are using Flash MX 2004 you will need to do one extra step:
For Flash MX 2004 Uses Only
- Go to: File > Publish Settings.
- Under Formats tick the: Flash box
- Click on the: Flash Tab
- Under Version select: Flash Player 6
- Click: OK
- Test you movie. It should now work correctly.
Note: You seem to be able to Publish in ActionScript Version 1 or 2.I have never know a Flash file not to work when published in a newer Player, but there is always a first time! I have looked at the code in detail and cannot see why it should not function as a Player 7 publication. When I have solved this puzzle I will update the tutorial.
Step nine: ActionScript for the Movie Clips
The ActionScript below makes sure that the Movie Clips follow the lead of Movie Clip 1.
- Place the following code on: Movie Clip 2
onClipEvent (enterFrame) {
_x = _root.MC1._x; // button 2 refers back to button 1
}
- Place the following code on: Movie Clip 3
onClipEvent (enterFrame) {
_x = _root.MC2._x
}
- Place the following code on: Movie Clip 4
onClipEvent (enterFrame) {
_x = _root.MC3._x
}
- Place the following code on: Movie Clip 5
onClipEvent (enterFrame) {
_x = _root.MC4._x
}
- Place the following code on: Movie Clip 6
onClipEvent (enterFrame) {
_x = _root.MC5._x
}
Note:
The code for MC 2 refers back to MC 1,
The code for MC 3 refers back to MC 2,
The code for MC4 refers back to MC3,
etc.
Step ten: Making the Menu Graphic Visible
At present the Menu Label is only visible in frame 1. It needs to be visible throughout the Movie:
- Right click in the last frame of the Menu Layer and select: Insert Frame
Step eleven: Making the Buttons Work
Although the Menu should now be working correctly the Buttons don't actually function. This last section will make them function correctly
- Open MC1 by double clicking on: Movie Clip 1
- Place the following code on: button 1
on (release) {
_root.gotoAndStop(10);
}
- Place the following code on: button 2
on (release) {
_root.gotoAndStop(20);
}
- Place the following code on: button 3
on (release) {
_root.gotoAndStop(30);
}
- Place the following code on: button 4
on (release) {
_root.gotoAndStop(40);
}
- Place the following code on: button 5
on (release) {
_root.gotoAndStop(50);
} - Place the following code on: button 6
// Note this goes back to frame 2 which is the first real frame or Home Page
on (release) {
_root.gotoAndStop(2);
}
Your Movie should have a Menu that swings in with buttons that go to different location in your Flash Movie. I hope you found this tutorial useful and easy to follow.

troika December 20, 2007 says:Hello!! have you already done that tutorial about menu that swings in? It works? I really canīt.... it's stay fixed.... off course smething is wrong but i almost certenaly that i have done everything right. Sorry my english, but can you help me and tell about your experience? Thanks










