PDA

View Full Version : Calling a function without an event


joe_T
07-05-2008, 08:50 PM
Hi
I need to call a function that accepts a mouseEvent (normally it is called when the user clicks a button).
But I need to call it without user clicking, so there is no mouse event to pass to it.

Meaning - how do I call:

function someHandler(event:mouseEvent):void

without any event?
Thanks
Joe

theclincher
07-05-2008, 09:18 PM
Umm I don't know if you can do that?

ASWC
07-05-2008, 09:30 PM
no matter how you call the function, something must trigger it. So what will trigger your function?

Dr.Mabuse
07-05-2008, 10:34 PM
If I understand you correctly you want to call a function in code, and through and event ?

protected function myMouseEvent(evt:MouseEvent = null):void
{
your code goes here...
}


this can now be called by your event, or in code like this:

myMouseEvent();

Was that what you wanted?

nikefido
07-06-2008, 02:17 PM
2 ways to get this done (altho you should find another solution :P )

1) Call the function and pass it a new mouse event


myFunction(new MouseEvent(MouseEvent.CLICK));


2) make the object listening for an event dispatch the event it is listening for

//if "obj" is the object listening for a mouse click
obj.dispatchEvent(new MouseEvent(MouseEvent.CLICK));