A Flash Developer Resource Site

+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    3

    Unhappy Website Submenu Problem (AS3)

    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.

    Here is a link to show what the menu looks like:

    http://www.kellyscreativesewing.ca/test.html

    All the links don't work yet so I suggest hovering over Contact and clicking the Google Maps button so you can see how it would work for all of them.

    Here is the code in the contact button movie clip:

    this.useHandCursor = true;
    this.trackAsMenu = true;
    this.stop();

    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 );
    }

    function over(e:MouseEvent){
    //e.stopImmediatePropagation();
    this.gotoAndStop(2);
    if( this.submenu !== '' && !sb ){
    var cn = getDefinitionByName( this.submenu );
    sb = new cn();
    sb.y = 50;
    sb.x = ( this.offset )? this.offset : 20;
    this.addChild( sb );
    }
    if( sb ){ sb.visible = true; }
    }
    function out(e:MouseEvent ){
    gotoAndPlay(1);
    if( sb ){ sb.visible = false; }
    }
    function down( e:MouseEvent ){
    gotoAndStop(3);
    }
    function up( e:MouseEvent ){
    gotoAndStop(2);
    }

    Here is the code in the sub-menu movie clip:

    stop();

    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:kellycarter@ns.aliantzinc.ca")
    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.

    Thanks for any feedback.

  2. #2
    Senior Member Steven FN's Avatar
    Join Date
    Mar 2010
    Location
    CA, USA
    Posts
    274
    Hi, can you upload a stripped down FLA or entire source? Because the code above isn't formatted correctly or is just missing some code.

  3. #3
    Junior Member
    Join Date
    Aug 2012
    Posts
    3
    Here is the source file.
    Attached Files

  4. #4
    Senior Member Steven FN's Avatar
    Join Date
    Mar 2010
    Location
    CA, USA
    Posts
    274
    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.
    Last edited by Steven FN; 08-19-2012 at 04:41 PM.

  5. #5
    Junior Member
    Join Date
    Aug 2012
    Posts
    3
    THANK YOU!

    I knew it would be such a simple solution. Thanks so much for helping me out it was the last thing keeping me from uploading this to the website.

    Also, I didn't actually need to use this:

    Code:
    this.addEventListener(MouseEvent.CLICK, contactusClick) // listen to main button and children
    The reason I didn't need it was because all of the listeners for the subMenu were in the actual movie clip and weren't part of the main buttons.

  6. #6
    Senior Member Steven FN's Avatar
    Join Date
    Mar 2010
    Location
    CA, USA
    Posts
    274
    Oh, so you didn't even need the main buttons to be clickable. Yeah, the less listeners the better. Glad i could help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts




Click Here to Expand Forum to Full Width


HTML5 Development Center