Skip to main content
Participating Frequently
November 20, 2013
Answered

HELP PLEASE!

  • November 20, 2013
  • 1 reply
  • 1354 views

I have tried making a drop down menu in both AS 2.0 and 3.0 and I get the same problem every time. I program it correctly so the drop down menu does what I want it to do, which is to drop down when you roll over the button, then retract once you mouseOut over the the hit button, however when you move the mouse too quickly away sometimes the drop down menu will stay open instead of retracting like it is supposed to do. I was wondering if there is some function or program that I can input that would be if the mouse is no longer over the menu area, that the menu will retract. I am open to any suggestion because I am a beginner in flash, and anything would help. Thank you in advance to whoever can help me!

This topic has been closed for replies.
Correct answer kglad

You are right, I do not want the contractraction to be on the about_btn, but when I programmed it using the recommendation you gave me, when the mouse leaves the about_menu, the menu contractacts upwards, which is great and thats what I need. However the about button that triggers the about menu is on a layer above the about menu, if you could imagine a rectangle inside of a box towards the top. So when the menu is triggered the menu comes out, but then if you roll over the button (which is no part of the menu) the menu goes away. Is there anyway to get rid of this problem? Do I have to add an additional function?


just add both the btn and menu to the hittest:

import fl.transitions.Tween;

import fl.transitions.easing.Regular;

import fl.transitions.easing.Elastic;

import flash.events.MouseEvent;

stop();

menu_cont.about_rect.alpha = 0;

menu_cont.about_btn.addEventListener(MouseEvent.ROLL_OVER, aboutRollOver);

var tween:Tween;

function aboutRollOver (event:MouseEvent):void {

tween = new Tween(menu_cont.about_menu, "y", Regular.easeOut, menu_cont.about_menu.y, 2.5, .5, true);

this.addEventListener(Event.ENTER_FRAME,loopF);

}

function loopF(e:Event):void{

if(!menu_cont.about_btn.hitTestPoint(mouseX,mouseY,true) && !about_btn.hitTestPoint(mouseX,mouseY)){

this.removeEventListener(Event.ENTER_FRAME,loopF);

aboutMouseOut();

}

}

function aboutMouseOut ():void {

tween = new Tween(menu_cont.about_menu, "y", Regular.easeOut, menu_cont.about_menu.y, -147.5, .5, true);

}

1 reply

kglad
Community Expert
Community Expert
November 20, 2013

you can trigger a loop (like enterframe) on mouseover that checks for a hittest between your menu and the mouse.  if negative, roll-up the menu and terminate the loop.

Participating Frequently
November 20, 2013

Thank you kglad, that is I think what I am looking for! Do you know by chance exactly how I would program that in AS 3.0?

kglad
Community Expert
Community Expert
November 20, 2013

menu.addEventListener(MouseEvent.MOUSE_OVER,overF);

function overF(e:MouseEvent):void{

//expand menu

this.addEventListener(Event.ENTER_FRAME,loopF);

}

function loopF(e:Event):void{

if(!menu.hitTestPoint(mouseX,mouseY,true)){

//contract menu

this.removeEventListener(Event.ENTER_FRAME,loopF);

}

}