attachMovie and variables

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?

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 …

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.

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.

Very nice discription sir.

thanks