- Home
- Tutorials
- Flash
- Intermediate
- Creating a Scrolling menu

Creating a Scrolling menu
The following tutorial will show you how to create scrolling menu. When you've got many pages in a website sometimes you might need to conserve space that'd be allocated for the long menu containing links to each page. With a scrolling menu you can conserve space as well as add some appeal to you're website. I'll be showing you how to create such a menu using Flash MX and ActionScript.
After you've opened up a new document, re-name the first default layer to "actions". Insert two more layers and name the second layer "background" and the third layer "menu". 
Select the "menu" layer and draw rectangle on the stage using the Rectangle tool. Select the whole rectangle and changle alpha to 60. With the whole rectangle still selected press F8 to convert it into a Movie Clip and give it the name "menu".

Double-click the the rectangle. Now just like above, select the whole rectangle and convert it into a movie and give it the name "button" with an instance name of "button0". There should be one layer in the timeline, Double-click it and re-name it to "button".
Insert another layer and name it "actions" and click, hold and drag that layer below the "button" layer. Select the first frame of the the "actions" layer and open up the Actions panel. When the Actions panel is opened, Copy-and-paste the following code in:
var tmi = 6;
var homeY = button0._y;
var homeW = button0._width;
var homeI = button0._x + homeW + 10;
/*
Duplicate the button tmi (total movie instances) times giving the newly duplicated movie a x location that is 10 pixels plus the width of the button
*/
for (i=1;i<tmi;i++)
{
button0.duplicateMovieClip("button"+i,i,{_x:homeI, _y:homeY});
homeI += homeW + 10;
}
Now select the "button" layer and then single click the button on the stage, open up the Actions panel again. Copy-and-paste the following code into it:
/*
Change size of button when button is hovered and change back when button hovers out
*/
on (rollOver) {
this._width += 10;
this._height += 10;
}
on (rollOut, dragOut) {
this._width -= 10;
this._height -= 10;
}
After you've pasted the code above, navigate back to the main timeline and select the first frame of the Actions layer, afterwards open up the Actions panel. When you've opened up the Actions panel Copy-and-paste the following code into it:
var bxi = 0; //Holds current speed of scrolling menu
var stageW = Stage.width;
/*
midStage holds the pixels located in the middle of the stage
*/
var midStage = mouseBuffer = stageW / 2;
/*
Declare a mouse listener object, have onMouseMove event handler point
to the directMenu function and then add listener via addListener(...)
*/
mouseListener = new Object();
mouseListener.onMouseMove = directMenu;
//Declare and define the directMenu function
Mouse.addListener(mouseListener);
function directMenu()
{
/*
mouseBuffer stores the x coordinate of the mouse point from the last
mouse move event. Then on the next mouse move the following code checks
the current x coordinate of the mouse pointer with the one previously
stored in the mouseBuffer and takes appropriate actions
*/
if (mouseBuffer > _xmouse)
{
/*
If mouseBuffer is greater that means that you moved left so move
so move menu right by adding to bxi. If the xmouse is less than the
the middle of the stage increase scrolling speed.
*/
bxi += (_xmouse < midStage) ? .2 : .1;
}
else if (mouseBuffer < _xmouse)
{
bxi -= (_xmouse > midStage) ? .2 : .1;
}
mouseBuffer = _xmouse;
}
When I got to this point I had already put in a background, but because of how nice it looked I decided to change the background which is why I figured I'd wait until the last part of the tutorial to have you put in a background. As I do with most my tutorials, I let you choose the background, if any, to allow you to be creative. Ok, now select the "background" layer and import your background image to the stage and position it appropriately.
Well, that concludes the tutorial and I'll omit a description of what the code does because the comment in the code does a fair job.
Spread The Word
Related Links
Attachments
20 Responses to "Creating a Scrolling menu" 
|
said this on 03 Mar 2007 2:03:26 AM CST
the code is incomplete, t
|
|
said this on 05 May 2009 3:29:02 PM CST
You are right, sorry-it w
Regards |
|
said this on 08 Mar 2007 2:08:28 AM CST
The bxi is used, fyi. It
|
|
said this on 16 Mar 2007 9:17:18 AM CST
Well guys I got a totally
I k //**Error** Symbol=me on &# **E on (rollOu Tota I am on Flash 8 professi |
|
said this on 06 Apr 2007 12:10:03 PM CST
You have put button event
|
|
said this on 30 Apr 2007 4:37:54 PM CST
How about if you want to
|
|
said this on 22 Jun 2007 9:25:27 AM CST
I love the look your tech
|
|
said this on 24 Jul 2007 11:13:28 AM CST
Sorry for the prolonged d
|
|
said this on 08 Nov 2007 10:03:09 PM CST
brian, i know what you me
cheers |
|
said this on 05 Dec 2008 6:50:25 PM CST
Very Nice tutorial.
It w |
|
said this on 07 Jan 2009 8:36:14 PM CST
Could you explain what ch
|
|
said this on 05 May 2009 3:27:54 PM CST
Yes. Modify the source so
|
|
said this on 09 Jan 2009 6:19:42 PM CST
This is really useless if
|
|
said this on 05 May 2009 3:15:46 PM CST
On the contrary, it's rea
|
|
said this on 13 Jan 2009 9:57:03 AM CST
I would like to know how
|
|
said this on 05 May 2009 3:24:08 PM CST
there is a variable named
The point i |
|
said this on 30 Aug 2009 11:29:18 PM CST
on(release){
getURL("typ } // select the bu |
|
said this on 08 Jun 2009 7:26:09 AM CST
this is great but it does
|
|
said this on 17 Jul 2009 7:34:01 AM CST
how would i go about con
Please i need desperat |
|
said this on 20 Aug 2009 10:28:35 AM CST
I would also add to it is
|



Author/Admin)