Calling Event Functions From Movieclips in Actionscript 2


In a flash movie I usually have a frame of actionscript that controls all elements in the file to keep everything in one place.

Sometimes I have an onPress(etc) function that refers to something happening in the scene when something is pressed, but what happens if we want another element to refer to that event for some reason?

Here’s an example of that code without anything “flashy”:

_root.myMC.onPress = function() {
  //code goes here
}

..and here’s our slightly more intersting flashy version:

_root.myMC.onPress = _root.funcOnPress = function() {
  //code goes here
}

So now we can call the following from another place in the code to call the same event’s function:

//somewhere else in our flash file
_root.funcOnPress()

That’s about it folks!
Now you can call things from other places.
Just remember to not use “_root” if you are including your final swf inside another swf.