# attachMovie and variables

**URL:** <https://forum.kirupa.com/t/attachmovie-and-variables/6196>\
**Category:** flash\
**Created:** [October 1, 2002, 6:42pm UTC](https://forum.kirupa.com/t/attachmovie-and-variables/6196 "2002-10-01T18:42:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bfrench](https://avatars.discourse-cdn.com/v4/letter/b/cdc98d/32.png) [@bfrench](https://forum.kirupa.com/u/bfrench)\
**Post date:** [October 1, 2002, 6:42pm UTC](https://forum.kirupa.com/t/attachmovie-and-variables/6196/1 "2002-10-01T18:42:53Z")

</div>

I normally don’t use Flash 5, so I’m kind of unfamiliar with it. But I have just a quick question. I have a movieclip that is accessed through attachMovie(). On this movie clip, two variables are created. After the movie clip is removed from the stage, I need to know the values of those variables. How do I get them?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 1, 2002, 7:06pm UTC](https://forum.kirupa.com/t/attachmovie-and-variables/6196/2 "2002-10-01T19:06:38Z")

</div>

If you define variables inside a MC instance, then those variables are local to that MC instance i.e. to reference the variables you have to target or address the MC. As a result if you delete the MC instance you delete the variables.

In your case, you need to record the variables outside the MC instance before you delete it. You could specify them on the \_root or main timeline - then they will remain accessible after the MC has been deleted.

If you don’t know how to target a MC, let me know and I’ll show you …

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 1, 2002, 7:42pm UTC](https://forum.kirupa.com/t/attachmovie-and-variables/6196/3 "2002-10-01T19:42:48Z")

</div>

Thanks for the reply. How do I store them on the main timeline? Also, they will need to be retrieved by a function that lives on the main timeline.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 1, 2002, 9:55pm UTC](https://forum.kirupa.com/t/attachmovie-and-variables/6196/4 "2002-10-01T21:55:06Z")

</div>

Flash operates a linear hierarchy denoted by dot notation which looks (and functions) a lot like JavaScript and other object-oriented languages.

At the lowest level is the \_root or main timeline. To declare a variable (var) on the main timeline you simply name the variable and assign a value to it e.g.

name=“peter”  
phoneNumber=444555

the paths to these variables from the main timeline are simply  
name  
phoneNumber

An instance of a movie clip (MC) is a nested timeline which operates independently of the main timeline. E.g. you can pause the main time line and a MC present will continue to play.

Each MC has a unique identifier or instance name - this is the path to the MC from the \_root timeline and any var in the MC is accessed by this path. E.g. suppose you have a MC instance called animationClip on the main timeline contining the variables name2 and phoneNumber2 then the paths to these variables from the main time line are  
animationClip.name2  
animationClip.phoneNumber2

The path to the main timeline from within the MC is \_root e.g. the path to the vars name and phoneNumber from within the MC would be  
\_root.name  
\_root.phoneNumber

A MC can contain another MC which can itself contain another MC and so on - like the russian dolls in each case the instance name is appended preceded by a dot. Following the preceding example if animationClip contained a MC instance called headAnimation and this MC contained a MC instance called eyeAnimation then the path from the main timeline would be  
animationClip.headAnimation.eyeAnimation

No matter how deep within a hierarchy of MC you are \_root will always bring you back to the main timeline. There is an additional target \_parent which will bring you back up one level in the hierarchy relative to your current position e.g. targeting \_parent inside the eyeAnimation MC will reference headAnimation.

Assuming you have the MC animationClip sitting on the main timeline and you want to record two variables speed and direction before you remove the clip then you would use something like

speed=animationClip.speed  
direction=animationClip.direction

Here you are defining the variables on the main timeline independent of the MC so the vars will exist after the MC has been deleted.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 2, 2002, 7:31am UTC](https://forum.kirupa.com/t/attachmovie-and-variables/6196/5 "2002-10-02T07:31:54Z")

</div>

Very nice discription sir.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 2, 2002, 1:37pm UTC](https://forum.kirupa.com/t/attachmovie-and-variables/6196/6 "2002-10-02T13:37:35Z")

</div>

thanks
