Be a Supporter!

AS3: call Function without Listener

  • 1,140 Views
  • 2 Replies
New Topic
simonhason
simonhason
  • Member since: May. 26, 2002
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
AS3: call Function without Listener 2012-04-16 20:20:25

I might be brain dead right now but I can't seem to get a function to call properly ... it's set up like this :

buttonZoomOut.addEventListener(MouseEvent.CLICK, zoomOut);

private function zoomOut(e:MouseEvent){
//bla bla
}

So the button calls the function fine, but I want to call the function from a separate script, kinda of like :

if(gameOver == true){
zoomOut();
}

can I call that function without using a new EventListener? Can it only be called from the MouseEvent on my zoomButton ?

Momo-the-Monkey
Momo-the-Monkey
  • Member since: Oct. 15, 2005
  • Offline.
Forum Stats
Member
Level 45
Musician
Response to AS3: call Function without Listener 2012-04-16 22:27:33

At 4/16/12 08:20 PM, simonhason wrote: I might be brain dead right now but I can't seem to get a function to call properly ... it's set up like this :

buttonZoomOut.addEventListener(MouseEvent.CLICK, zoomOut);

private function zoomOut(e:MouseEvent){
//bla bla
}

So the button calls the function fine, but I want to call the function from a separate script, kinda of like :

if(gameOver == true){
zoomOut();
}

can I call that function without using a new EventListener? Can it only be called from the MouseEvent on my zoomButton ?

Yes, just modify the function zoomOut for an optional parameter

private function zoomOut(e:MouseEvent = null){
     // etc
}

That way anyone can call it, and everyone is happy.

For future reference, Flash and Actionscript questions belong in the Flash Forum.


Hello, from the past!
[ PHP: Main ]

BBS Signature
simonhason
simonhason
  • Member since: May. 26, 2002
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS3: call Function without Listener 2012-04-16 23:25:40

Everyone is happy INCLUDING ME :D Thanks for your help! And my mistake, I'll make sure I am in the proper thread next time.