-
Multiple event listeners
I've got 5 buttons (btn1_mc, btn2_mc, etc.) that I need to assign the same listeners to for the RollOver and RollOut to go to frame 2 and back to 1, and I'm sure there's a better way to do it than this, but I can't get it working...
I started with:
Code:
nav1_mc.nav2_mc.btn1_mc.addEventListener(MouseEvent.CLICK, slidePanelOutClick);
nav1_mc.nav2_mc.btn1_mc.addEventListener(MouseEvent.MOUSE_OVER, nav2RollOver);
nav1_mc.nav2_mc.btn2_mc.addEventListener(MouseEvent.MOUSE_OVER, nav2RollOver);
nav1_mc.nav2_mc.btn3_mc.addEventListener(MouseEvent.MOUSE_OVER, nav2RollOver);
nav1_mc.nav2_mc.btn4_mc.addEventListener(MouseEvent.MOUSE_OVER, nav2RollOver);
nav1_mc.nav2_mc.btn5_mc.addEventListener(MouseEvent.MOUSE_OVER, nav2RollOver);
nav1_mc.nav2_mc.btn1_mc.addEventListener(MouseEvent.MOUSE_OUT, nav2RollOut);
nav1_mc.nav2_mc.btn2_mc.addEventListener(MouseEvent.MOUSE_OUT, nav2RollOut);
nav1_mc.nav2_mc.btn3_mc.addEventListener(MouseEvent.MOUSE_OUT, nav2RollOut);
nav1_mc.nav2_mc.btn4_mc.addEventListener(MouseEvent.MOUSE_OUT, nav2RollOut);
nav1_mc.nav2_mc.btn5_mc.addEventListener(MouseEvent.MOUSE_OUT, nav2RollOut);
back_mc.addEventListener(MouseEvent.CLICK, backOut);
function nav2RollOver(mevt:MouseEvent):void {
trace("MOUSE_OVER "+mevt.currentTarget.name);
nav1_mc.nav2_mc.btn1_mc.gotoAndStop(2); //this was the only way it worked, but only on the one clip
//mevt.currentTarget.name.gotoAndStop(2);
//mevt.currentTarget.gotoAndStop(2);
}
function nav2RollOut(mevt:MouseEvent):void {
nav1_mc.nav2_mc.btn1_mc.gotoAndStop(1);
}
It only seems to work when you roll completely off a clip and back on and it just flashes the rollover, it doesn't stay on frame 2?? If I roll from one item right to the other, it doesn't trigger the trace on the successive objects...
There's GOT to be an easier way to do this....
-
Something like this would shorten your script:
for (var i:int = 1; i<5; i++)
{
nav1_mc.nav2_mc["btn" + i + "_mc"].addEventListener (MouseEvent.MOUSE_OVER, nav2RollOver);
}
-
I just tried one of your commented out lines and it worked fine.
I put some buttons on the stage, named them "btn0" through "btn9" and put this in the timeline actions...
PHP Code:
for(var i:uint = 0; root["btn"+i]; i++){
root["btn"+i].addEventListener(MouseEvent.MOUSE_OVER, mor);
root["btn"+i].addEventListener(MouseEvent.MOUSE_OUT, mot);
}
function mor(e:MouseEvent):void
{
e.currentTarget.gotoAndStop(2);
trace('over '+e.currentTarget.name);
}
function mot(e:MouseEvent):void
{
e.currentTarget.gotoAndStop(1);
trace('off '+e.currentTarget.name);
}
its very simplified, but does what you're trying to do.
-
also, you could try something like this...
var mc:Object = nav1_mc.nav2_mc.getChildByName(mevt.currentTarget. name);
mc.gotoAndStop(2);
-
Why don't you just set the buttonMode=true for your btn_mcs and create frame labels "_up", "_over"?
http://livedocs.adobe.com/flash/9.0/...lass-list.html
-
SWEET!!! You guys rock!! I knew there was a way to do it, but the switch to AS3 is giving me some issues. :)
Ralgoth, I used your first solution because I have some other things I need to do other than just over/out state. It's much closer, but I'm still having some other issues.
My rollover state is just frame 2, my rollout state is frame 1. The rollover works, but it flickers constantly, it doesn't stay in the rollover state...any ideas?
Also, I need to pause a video that is under each of the buttons (button named clip1Btn_mc and video named clip1_mc, so I tried adding a property to the button to get the number, but it doesn't seem to work, although, hardcoding the path does work...here's the code:
Code:
//your for loop...thank you VERY much...
for(var j:uint = 1; j<=9; j++){
movieGroup_mc.movie_mc["clip"+j+"Btn_mc"].addEventListener(MouseEvent.ROLL_OVER, stopClip);
movieGroup_mc.movie_mc["clip"+j+"Btn_mc"].addEventListener(MouseEvent.ROLL_OUT, playClip);
movieGroup_mc.movie_mc["clip"+j+"Btn_mc"].numJ=j;
}
function stopClip(mevt:MouseEvent):void {
//this does trace out correctly
trace("MOUSE_OVER "+mevt.currentTarget.numJ);
//this goes to frame 2 of the button, but it flickers like crazy
mevt.currentTarget.gotoAndStop(2);
//this doesn't stop any of the videos
movieGroup_mc.movie_mc["clip"+mevt.currentTarget.numJ+"_mc"].stop();
//but this DOES stop the one video
movieGroup_mc.movie_mc.clip1_mc.stop();
}
function playClip(mevt:MouseEvent):void {
mevt.currentTarget.gotoAndPlay(1);
movieGroup_mc.movie_mc["clip"+mevt.currentTarget.numJ+"_mc"].play();
}
Thanks!!!
-
Ah...nevermind...lol...my rollover state was just a border with no fill, so it was constantly hitting the rollover/out state...put a transparent fill in there and it works GREAT!!!
Thanks!!!