Hey everyone,
I was wondering, is it possible to call a function in a MC from the _root of the movie?
I have an MC called timer, linked aswith a function in it,
testFunc = function(){
trace("It Worked!");
}
On the _root in the first frame I have this,
_root.attachMovie("timer","t",5);
_root.t.testFunc();
This don’t work, what am I doing wrong and how can I get it working?
Thanks in advance for helpful replys.
The code on the root runs before that in a movie clip so you are trying to call the function before it is created.
That makes sense, how would I get around this then?
Sorry to bump but can anyone anwser my question, I really want to start coding my game.
You could just call your function in the same scope where it is loacted.
How do you mean, create the function on the root rather than in the MC and call it on the Root?
No I meant create it and call it in the timeline of the movie clip.
Then if I get to a certain point in my movie on the main timeline, I can’t call it from the root. I guess I could put the call on a seperate in the mc and use,
_root.t.gotoAndStop(“tFunc”) //this frame has the call
Is there no other way? If not i’ll stick with that and thanks for your help so far.
But if you decide to call it later on in the time line you won’t have a problem since the function will already be defined - the problem arises when you try to call the function before the movie clips actions have run, but one frame after instantiationyou can call the function anyway, anyhow, anywhere you choose.
Thanks for all the advice TheCanadian, you’ve been a great help.
Going to start working on my game now, gota recode it all because the first version was a mess, i’ll post it up when its playable again so you can see.
Thanks again.