Calling event functions from movieclips in actionscript 2

0 min read 147 words

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.

Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags