Just spotted this quandary on the forums regarding calling an Actionscript 3 function on the main timeline of Flash from inside of another movieclip. This is one of my favorite type questions to answer because I had about a 50/50 chance of actually remembering how it was done without looking in some old .fla to find the last place I’d done this. And today I got it right…
Paste this onto a frame in the main timeline of your .fla…
function mainTimeline() {
trace (“yo, I’m a function on the main timeline. If you are reading this, I was called by script inside a movieclip”);
}
Now use any movieclip you have onstage, and double click into it’s timeline and paste the following on a frame…
MovieClip(parent).mainTimeline();
Thats it. Totally done. If you publish, that trace statement will get called and you’ll see it in the Output window.
Alright what if you wanted to call this function from 2 mc’s deep. Like one movieclip inside of another. The code is…
MovieClip(parent.parent).mainTimeline();
MovieClip(parent).cartoonsmart.x = 400;MovieClip(parent).cartoonsmart.gotoAndPlay(2);
Filed under: Coding














A better way to go if you want to stick to OOP best practices:
http://www.calypso88.com/?p=301
(page 1 has your method described above)
Wow, my hours of scouring the web are over!!! Thanks for this, it fixed a problem I was having when I was creating a menu!!!
Thanks for this excelent tip Justin. Been looking all over the web to find a solution to several problems I’ve had lately and your tip solved all of them. CHEERS!
Cool this was my post, I’m famous!
Ok… what if i need to trigger the method from a loaded MC… I mean i loaded an MC using LOADER and i just cant call the method the container has…
What’s the error when you try?
Hello Justin!
Thanks for this cool tip. You made me happy and I’ll in turn make my client happy
Thanks you saved my ass