Reputation: 277
I have a menu that is built using its own AS3 class, when a link in this menu is clicked it fires a function according to some variables passed in from an external XML file.
The menu is made up of four subsections and I want the user to be able to jump to the parent of that subsection from a button that is completely separate from that menu.
What I'd theoretically like to do is trick the parent button into thinking it's been clicked when the user clicks one the buttons in this other menu.
Does that make any sense? Is this even possible? I'm tearing my hair out trying to think of a work-around, but I have to admit that I'm relatively new to OOP and am a little lost when it comes to passing variables, never mind passing them between classes!
Upvotes: 2
Views: 8542
Reputation: 3851
buttonToTarget.addEventListener(MouseEvent.CLICK, doThisFunction, false, 0, true);
buttonToTarget.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
This will perform a fake mouse click on the button you are wanting to act as being clicked.
Upvotes: 5
Reputation: 1302
if you want to trigger the MouseEvent.MOUSE_DOWN
event for a movieclip in the menu, you can do so directly:
path.to.parentButton.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, true, false, localX,localY));
You can omit the localX and localY if the recipient of the event never checks it.
Upvotes: 2