I'm having a problem trying to finish a flash menu for a website. The problem is that when you click on a sub-menu button, it will open the link to that button but it will also open the link to the main menu button (movie clip) it is attached to.
I am using component definitions to put a certain sub-menu with a certain main-menu button. The code I'm writing is in each main-menu button movie clip, there is also a bit of code in the sub-menu movie clip as well just for linking the websites for each of the sites for those sub-menu buttons, but not the main-menu button.
var sb = false;
var getContactUs:URLRequest = new URLRequest("http://www.kellyscreativesewing.ca/contact_us.htm")
this.addEventListener(MouseEvent.CLICK, contactusClick)
function contactusClick(event:MouseEvent):void{
navigateToURL(getContactUs, '_self');
}
this.addEventListener( MouseEvent.ROLL_OVER, over );
this.addEventListener( MouseEvent.ROLL_OUT, out );
if( !this.submenu ){
this.addEventListener( MouseEvent.MOUSE_DOWN, down );
this.addEventListener( MouseEvent.MOUSE_UP, up );
}
var getGoogleMaps:URLRequest = new URLRequest("http://maps.google.ca/maps?f=q&source=embed&hl=en&geocode=&q=B2W+3V1&aq= &sll=44.697633,-63.487909&sspn=0.005834,0.013937&ie=UTF8&hq=&hnear =Dartmouth,+Nova+Scotia+B2W+3V1&t=h&ll=44.698189,-63.488531&spn=0.007321,0.013733&z=16")
btn_googlemaps.addEventListener(MouseEvent.CLICK, googlemapsClick)
function googlemapsClick(event:MouseEvent):void{
navigateToURL(getGoogleMaps, '_blank');
}
var getEmail:URLRequest = new URLRequest("mailto:[email protected]")
btn_email.addEventListener(MouseEvent.CLICK, emailClick)
function emailClick(event:MouseEvent):void{
navigateToURL(getEmail, '_self');
}
var getNewsletter:URLRequest = new URLRequest("http://www.kellyscreativesewing.ca/newsletter.htm")
btn_newsletter.addEventListener(MouseEvent.CLICK, newsletterClick)
function newsletterClick(event:MouseEvent):void{
navigateToURL(getNewsletter, '_self');
}
I hope someone would be able to help, I have a feeling it has to either do with trying to create an if statement that would force it to open one or the other, or that I'm putting the code for the website links in the wrong places or that maybe trackAsMenu isn't working and it's the reason they both open.
I think the problem is that the subMenu is a child of the main buttons. So, when its clicked there are 2 functions firing at the same time. Because subMenu is a child, on click it is still part of the main button, so both functions are executed.
An easy way to remedy this is to have a Button or MovieClip for the main button with instance name. That way the main button has its own specific object to listen to.
Code:
this.addEventListener(MouseEvent.CLICK, contactusClick) // listen to main button and children
contactBtn.addEventListener(MouseEvent.CLICK, contactusClick) // listen to only contactBtn inside of "buttonmc Contact"
You will probably need to do it to all the main buttons, an easy way to accomplish this would be to have an invisible MovieClip that you can just reuse for all of them.