Groups | Blog | Home
all groups > flash actionscript > november 2006 >

flash actionscript : Scrolling Menu


Jose Guevara
11/17/2006 5:22:02 PM
Not sure what you are trying to do. Is this supposed to be a menu
oscillating left to right based on mouse position?

Anyhow, based on your condition if _x is under 0 or above 675, it stops
working. Your calculation for the new _x might allow _x to go negative or
above 675, so you have to make sure it doesn't...

I'm not sure of what you are trying to do so this might not be what you're
looking for...

_root.onEnterFrame = function() {
if (menu_mc._x >= 0 && menu_mc._x <= 675) {
var newX = menu_mc._x+(0.5*Stage.width-_root._xmouse)/10 ;
if ( newX < 0 ) newX = 0 ;
if ( newX > 675 ) newX = 675 ;
menu_mc._x = newX ;
}
};


[quoted text, click to view]

Mister Peanut
11/17/2006 8:23:14 PM
Hi all,

if anyone could point me in the right direction, I think I have a simple
problem. I have a scrolling menu graphic containing buttons. I have the
scrolling function working well, but am trying to make it stop when the graphic
scrolls to its ends. I have surrounded my script in an if statement so that
the code only executes when my menu_mc reaches the end. This doesn't work.

Here is the code I am using:

_root.onEnterFrame = function () {
if (menu_mc._x > 0 && menu_mc._x<675){
menu_mc._x = menu_mc._x + (0.5 * Stage.width - _root._xmouse)/10;
}
}

my menu_mc is behind a mask, and is 675 pixels wide.
Not sure what my problem is, I have difficulty with AS. Do I need an event
listener to listen to when my mc goes beyond certain boundaries? If so, could
someone help me with how to use this?

Cheers for any tips.

P
Mister Peanut
11/17/2006 11:24:27 PM
Thanks for the quick reply.

I will explain what I want to do a little more clearly.
My goal is to have a scrolling graphic with buttons on it. As you move the
mouse left, the graphic moves right. As you move the mouse right, the graphic
moves left. This is a very common menu style; I have seen it on many websites.
using this code alone:

_root.onEnterFrame = function () {
menu_mc._x = menu_mc._x + (0.5 * Stage.width -_root._xmouse)/10;
}

I get what I want, except my menu_mc continues to scroll indefinitely. All I
want to do is have the menu_mc stop scrolling when it reaches its edge.

So, using the code that you gave me, the menu stops scrolling left when it
reaches the rightmost edge, but then it no longer works when I move the mouse
back over the menu_mc to scroll right.

I am confused, I will keep trying to work it out.

P
Jose Guevara
11/18/2006 11:02:48 AM
Do you have a sample online that I can look at?

The code I had sent you was with:
a menu_mc 675px wide with the registration of this mc being in the center.
When you move the mouse left the menu_mc moves right and vice versa. With
the registration at the center the menu stops scrolling when its center
reaches 0px on the main timeline or 675px. So you end up seeing half of the
mc on the right or the left side of the stage.

http://www.guevara.net/forums/

JG

[quoted text, click to view]

Jose Guevara
11/20/2006 12:33:53 PM
I'm glad you got it to work :-)

JG

[quoted text, click to view]

Mister Peanut
11/20/2006 5:33:02 PM
Ahhh, Thank you, Jose.

It was the registration point that had me thrown off. I changed it to centre, and it works how I would like it to. It all makes sense now!

Cheers,
Mister Peanut
11/21/2006 12:16:41 AM
All right. Second stab at a new problem. (there was an error after hitting
reply, and my last message was lost...)

The menu works fine now, and I have named it scroller.swf. What I want to
do is load scroller.swf into another swf. I have used loadMovie to do this.
No problems here. I can load the movie fine into my other swf file, except I'm
getting one frustrating problem; the center of my scroller.swf changes to the
center of my stage. so now, the scroller reads the mouse position of the new
stage, and not the scroller.swf stage like I want it to.

I have used _lockroot = true(); with success in the past to make sure my swf
retains all of its own functionality, however, this is not working as it
usually does. Is there something obvious that I'm doing wrong? I have tried
changing the registration point of the movie container I am loading
scroller.swf into, and tried changing the center of my original file as well.
Nothing seems to take the center off of my new swf, and change it to my loaded
scroller.swf.

Any suggestions greatly appreciated.

P
Mister Peanut
11/21/2006 5:48:15 PM
Okay, I am gradually working my way through this problem, but I still need a
little help. I have readjusted the numbers, and it seems to be working well.
I am no longer loading scroller.swf into an empty movie clip. I have the FLV
player and the scroller in different layers in the same swf. This is the code
that works:

_lockroot = true();



_root.onEnterFrame = function() {
if (menu_mc._x >= 115 && menu_mc._x <= 860) {
var newX = menu_mc._x+(0.5*1300-_root._xmouse)/10 ; //Stage.width-_root
1300 = half of 1300 is centre point of scroll action.
if ( newX < 115 ) newX = 115 ;//115 adjusts the right side of clip
if ( newX > 860 ) newX = 860 ;//860 adjusts the left side of clip
menu_mc._x = newX ;
}
}

In order to stop the scrolling action from occurring when the mouse was not
over the menu_mc, I tried adding to the first line of script:

menu_mc.onRollOver = function(){

// with my code above placed here

}

This, however, has removed the function of the buttons, but has retained the
scrolling action. If anyone has any ideas as to why the buttons no longer
work, I'd greatly appreciate it!

P
Mister Peanut
11/28/2006 12:19:25 AM
Please, if anyone can point me in the right direction, I'm still stuck on this.

Cheers,

AddThis Social Bookmark Button