views:

19

answers:

0

I have a minor issue accessing declared variables in nested timeslines that are loaded using the attachMovie() method, and I could do with some help.

I'm running an experiment where I load a container dynamically at runtime using attachMovie(). In this container, there is a test variable called 'testvar' that I set with something arbitrary, like "hello". In the main timeline, I run a trace to try and access this variable.

Now, I have two traces running, one in the main timeline, and one in the container. The code for the main timeline looks as follows:

stop();

init = function() {
wall = attachMovie("container", "container", 0);
wall._width = 400;
wall._x = 0;
wall.y = 0;
trace(_root.container.testvar);
}

init();

In the container clip loaded by AS2 the code is:

stop();
var testvar = "hello";
trace(_root.container.testvar);

Now, if I run this code, the first trace (from the main timeline) returns as "undefined", while the second trace (in the container) returns with the proper value. I've tried changing the syntax for the main timeline trace to things like trace(wall.testvar), trace(_level0.container.testvar) etc with no luck.

The only way I've managed to get both traces to return the value is if I set the value of container.testvar from within the init() function, and by not setting the variable from within the container, like so:

stop();

init = function() {
var count = this.count;
wall = attachMovie("container", "container", 0);
wall._width = 400 * count;
wall._x = 0;
wall.y = 0;
wall.testvar = "hello"
trace(_root.container.testvar);
}

init();

and in the container:

stop();
var testvar;
trace(_root.container.testvar);

However, this isn't what I want to do. What I need is to be able to access variables that have values set already at runtime, using the original code.

Is this just a quirk of Flash and AS2, or is my syntax a little wrong? Help, please!