Skip to content

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 }
Code language: JavaScript (javascript)

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

_root.myMC.onPress = _root.funcOnPress = function() { //code goes here }
Code language: JavaScript (javascript)

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()
Code language: JavaScript (javascript)

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.

See also  How to perform Array Element Parity in Golang
Notify of
1 Comment
Oldest Most Voted
Inline Feedbacks
View all comments
Raghib suleman
12 years ago

thanks for nice tips

Would love your thoughts, please comment.x