We help IT Professionals succeed at work.

Child object calls MouseEvent as well.....ending up calling MouseEvent twice.


So I created this MovieClip in order to create a dynamic button.  Inside the MovieClip, I have a dynamic TextField.

Basically, when I dynamically put the buttons on stage, I can assign different text to the button depending on what my array contains.

I have a couple problems...
First of all, visually, I dont like what the mouse pointer is doing when it is over the button. When the mouse is over the button, it looks like an Arrow (your normal mouse pointers)...but slide it into the middle where the DynamicTextField resides, and the Mouse turns into a cursor. Its distracting.

Secondly, the MouseEvent. After creating the button dynamically and adding a listener to it, it calls the listener TWICE as you run your mouse pointer over the button. It calls the listener when the pointer is over the button, and then it calls the listener again as the pointer is over the DynamicTextField.

Is there a way around this, or someway I can make it behave like the single button its supposed to be? Its like clicking twice when you really only needed to click once. And as the MouseEvent deletes some objects on stage, running it twice produces unpredictable behaviour.

Thanks in advance!

The problem I am having is on the MouseEvent.
Watch Question

Kim WalkerWeb Programmer/Technician

Is the mouse event assigned to the movie clip or the elements inside the movie clip?
Hi, the mouse event is assigned to the Array MenuArray, which contains the MovieClips, which contains the Textfields. This way I can create new buttons on the fly by adding new array elements.


MenuArray[v] = new DynamicButton();
MenuArray[v].DynamicMenuText.text = "text goes into the buttons";
MenuArray[v].addEventListener(MouseEvent_______________ )

The DynamicButton and the DynamicMenuText is created in the library, while the array is created in script.
Kim WalkerWeb Programmer/Technician

You're actually assigning it to the individual movieclip which happens to be in an array which looks right.

What is MenuArray[v].DynamicMenuText.type? It should be "dynamic" but it sounds like it may be "input" if the pointer is changing to a cursor.
I am attaching here a simple demo...

Not sure why the mouse pointer doesnt change into a cursor in this one, but as you can see, as you run your mouse over the text it calls the MouseEvent again.

Oh sorry didnt see your response there.

The MenuArray[v].DynamicMenuText.type is dynamic, i checked it both in the library and traced it.
As you can see in my attached file, even when the code is simplified to a one MovieClip in the library and no arrays and assigning content and all that, the MouseEvent is called multiple times as you trace your mouse pointer over the button.

I hope this is not normal flash behaviour lol....I may be in trouble.

If there is no solution, i would also consider workarounds....
What I am trying to do , is create a dynamic Menu. User enters text in an XML file, and tags them as a primary menu or a submenu. This then gets read into an array, where the menu is then build.

The text tagged as primary menu is assigned to the DynamicMenuText, and an event is added to the menu buttons so that when user mouse over a primary menu, the submenu for that particular menu pops up, while removing the previous submenu that may have been on the screen while the user mouses over other primary menus.

So the failing at this point is to remove these submenus...as the MouseOver Event is called multiple times, flash tries to remove sub menus that does not exist anymore, giving me all sorts of random behaviour.

Web Programmer/Technician
It stays an arrow for me regardless of whether I'm over the text field or not. This can be fixed by setting the useHandCursor and button mode to true and setting the mouseEnabled property of your dynamic text field to false.

button.buttonMode = true;
button.useHandCursor = true;
button.testtext.mouseEnabled = false;

Open in new window

And finally, you may want to change your event from a MOUSE_OVER to a ROLL_OVER. This prevents the text field from firing the event again, but doesn't prevent the cursor from changing to a pointer. However, setting mouseEnabled to false does both, so this is totally optional.

button.addEventListener(MouseEvent.ROLL_OVER, huh);

Open in new window


Didnt know of all these functions. You saved me having to put a counter in each event fired to see who fired it. :)


Explore More ContentExplore courses, solutions, and other research materials related to this topic.