PDA

View Full Version : horizontal scrolling menu scrolls left/right but scrolls entire stage with content


frank_n
01-14-2009, 03:36 PM
hallo,

I am stuck since 2! days with this problem:

at main timeline there is front_mc. if ones mouse is over this menu it scrolls left/right according to mousemovement. works great.
inside the front_mc are the buttons which call via gotoAndStop the content on stage on this timeline not the Main TL.
The problem is, if content got called and is on the stage and I move again to the menu, the content scrolls horizontal analogue to the menu with the menu, but of course, only the menu should scroll.

How can I solve this?

the code for the parallaxing scrolling of front_mc and back_mc:


front_mc.addEventListener(MouseEvent.MOUSE_MOVE,f) ;
var t:Timer=new Timer(40,0);
t.addEventListener(TimerEvent.TIMER,moveF);
function f(e:MouseEvent) {
t.stop();
t.start();
}
var speed:Number = .9;

function moveF(e:TimerEvent) {
front_mc.x =speed*front_mc.x+(1-speed)*(stage.stageWidth-front_mc.width)*root.mouseX/stage.stageWidth;
back_mc.x = speed*back_mc.x+(1-speed)*(stage.stageWidth-back_mc.width)*root.mouseX/stage.stageWidth;
if (Math.abs(front_mc.x- (stage.stageWidth-front_mc.width)*root.mouseX/stage.stageWidth)<1 && Math.abs(back_mc.x-(stage.stageWidth-back_mc.width)*root.mouseX/stage.stageWidth)<1) {
front_mc.x = (stage.stageWidth-front_mc.width)*root.mouseX/stage.stageWidth;
back_mc.x = (stage.stageWidth-back_mc.width)*root.mouseX/stage.stageWidth;
t.stop();
}
e.updateAfterEvent();
}



it would be so great if one can shed light on this, I read through so many threads.

RefreshGFX
01-14-2009, 10:00 PM
So, if I understand correctly you have ...

1) A main time line (let's call that "_root" or "root")
2) A main movie-clip called "front_mc"
3) Inside "front_mc" are your navigation buttons.
4) Also inside "front_mc" are your content movie-clips.

The code you provide in your post has a "back_mc" - what is this used for?

Regardless, if my first 4 assumptions above are correct then it appears when you move your mouse "front_mc" will move accordingly. And if all your navigation and content is inside "front_mc" then you should expect it all to move together.

What you would need to do is to somehow separate your navigation from your content. There are several ways to do that. For instance - simply by moving your content to the _root timeline and putting it in a separate movie-clip from "front_mc" would separate it from being affected my your _x moving script.

frank_n
01-15-2009, 02:36 PM
Hei,

thank you very much for your hint RefreshGFX, I will explain it:

on root there is front_mc which gets scrolled via the code above - it is the scrolling menu, moving left and right depending on mouse movement over front_mc.
inside this clip are the buttons nested. if clicked, they gotoAndStop() to a frame inside the timeline of front_mc, because the buttons are nested in front_mc.
-> now, the entire content scrolls with the menu, the front_mc

How could I refer from the buttons outside this timline to root-timeline? -parent.parent.addChild() ? and exporting the content as class?

button1_btn.addEventListener(event.MouseEvent.CLIC K), playbutton1_btn;
function playbutton1_btn(event)
{
parent.parent.gotoAndStop("Marker1");
}
this didnt work,somehow

maybe you have a further advice, which would be much appreciated.

RefreshGFX
01-15-2009, 05:06 PM
I think you're over complicating the issue. If you want to target the _root (main) timeline from anywhere (For instance: It could be from a mc, inside a mc, inside a mc, inside a mc, inside front_mc). It would simply be "_root".

So, let's say you have a navigation button inside "front_mc" called "button1_btn"...

You could just say...

button1_btn.onRelease = function(){
_root.gotoAndStop("Marker1");
_root.content_mc.gotoAndStop("Marker1");
_root.content_mc.another_mc_in_content_mc.gotoAndS top("Marker1");
// "_root" will always get you back to the main timeline
};

One other thought... Think of "Parent" as one item up from where you are currently at. So... the "_parent" of "front_mc" is technically the main timeline ("_root").

Also, I currently only code in AS 2.0 - So, that code requires an underscore before "_parent" or "_root"... I THINK (??) the underscore is left out in AS 3.0 (so, just ... "root"). I'm just saying ... if you're using AS 3.0 - you should confirm this before using my AS 2.0 code

Hopefully, that helps.

frank_n
01-16-2009, 02:15 PM
thanks again, your code wasn't right, but you put me in the right directions. indeed I thought to complicated.

since _root.gotoAndStop(); from AS1-2 got removed, the easiest way in Actionscript3 AS3 to reference e.g. a Button inside a mc to call content to stage is

MovieClip(root).gotoAndStop("Marker1");

I thought I don't have a Movieclip on the Main Timeline MTL, but it realy works, set it as the action for your nested buttons and you are free from surprises: like in my case :)

I nested the scrolling menu (front_mc) inside a mc on MTL and the content gets called on the mainstage, without being hijacked by my moving front_mc

thank you man.

RefreshGFX
01-16-2009, 08:57 PM
Hmmm. Cool. Glad I was able to help.

And thanks for the tip on AS 3.0 - I've been hesitant to jump into it ... Because, people I talk to in the "real-world" say it's "completely different". But, your code doesn't look as difficult as everyone I talk to suggests. Yeah, it's only one example - but, from what I can see AS 3.0 - looks pretty straight-forward. So... Thank you - too ;-)

Peace.