# Calling a Function in an MC from \_root

**URL:** <https://forum.kirupa.com/t/calling-a-function-in-an-mc-from--root/183313>\
**Category:** flash\
**Created:** [March 25, 2006, 7:11pm UTC](https://forum.kirupa.com/t/calling-a-function-in-an-mc-from--root/183313 "2006-03-25T19:11:07Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alpha\_eX](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@Alpha\_eX](https://forum.kirupa.com/u/Alpha_eX)\
**Post date:** [March 25, 2006, 7:11pm UTC](https://forum.kirupa.com/t/calling-a-function-in-an-mc-from--root/183313/1 "2006-03-25T19:11:07Z")

</div>

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,

```auto
testFunc = function(){
     trace("It Worked!");
}

```

On the \_root in the first frame I have this,

```auto
_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.

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [March 25, 2006, 7:41pm UTC](https://forum.kirupa.com/t/calling-a-function-in-an-mc-from--root/183313/2 "2006-03-25T19:41:58Z")

</div>

The code on the root runs before that in a movie clip so you are trying to call the function before it is created.

---

<div class="post-metadata">

**Author:** ![Alpha\_eX](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@Alpha\_eX](https://forum.kirupa.com/u/Alpha_eX)\
**Post date:** [March 25, 2006, 8:00pm UTC](https://forum.kirupa.com/t/calling-a-function-in-an-mc-from--root/183313/3 "2006-03-25T20:00:02Z")

</div>

> [@TheCanadian](#):
>
> 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?

---

<div class="post-metadata">

**Author:** ![Alpha\_eX](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@Alpha\_eX](https://forum.kirupa.com/u/Alpha_eX)\
**Post date:** [March 25, 2006, 10:58pm UTC](https://forum.kirupa.com/t/calling-a-function-in-an-mc-from--root/183313/4 "2006-03-25T22:58:02Z")

</div>

Sorry to bump but can anyone anwser my question, I really want to start coding my game.

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [March 26, 2006, 12:02am UTC](https://forum.kirupa.com/t/calling-a-function-in-an-mc-from--root/183313/5 "2006-03-26T00:02:55Z")

</div>

You could just call your function in the same scope where it is loacted.

---

<div class="post-metadata">

**Author:** ![Alpha\_eX](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@Alpha\_eX](https://forum.kirupa.com/u/Alpha_eX)\
**Post date:** [March 26, 2006, 12:04am UTC](https://forum.kirupa.com/t/calling-a-function-in-an-mc-from--root/183313/6 "2006-03-26T00:04:11Z")

</div>

> [@TheCanadian](#):
>
> 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?

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [March 26, 2006, 12:09am UTC](https://forum.kirupa.com/t/calling-a-function-in-an-mc-from--root/183313/7 "2006-03-26T00:09:46Z")

</div>

No I meant create it and call it in the timeline of the movie clip.

---

<div class="post-metadata">

**Author:** ![Alpha\_eX](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@Alpha\_eX](https://forum.kirupa.com/u/Alpha_eX)\
**Post date:** [March 26, 2006, 12:16am UTC](https://forum.kirupa.com/t/calling-a-function-in-an-mc-from--root/183313/8 "2006-03-26T00:16:21Z")

</div>

> [@TheCanadian](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [March 26, 2006, 1:39am UTC](https://forum.kirupa.com/t/calling-a-function-in-an-mc-from--root/183313/9 "2006-03-26T01:39:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Alpha\_eX](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@Alpha\_eX](https://forum.kirupa.com/u/Alpha_eX)\
**Post date:** [March 26, 2006, 1:41am UTC](https://forum.kirupa.com/t/calling-a-function-in-an-mc-from--root/183313/10 "2006-03-26T01:41:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [March 26, 2006, 1:43am UTC](https://forum.kirupa.com/t/calling-a-function-in-an-mc-from--root/183313/11 "2006-03-26T01:43:18Z")

</div>

Glad to help :hoser:
