Skip to main content
Participating Frequently
June 7, 2006
Answered

setInterval and attachMovie

I'm using setInterval to attach a variable number of movies. When I input the code below, the call to the function works by itself and within set interval, but the trace gives me:

_level0.blocksHolder.randomNumberDisplay
undefined
undefined
undefined

with undefined produced the correct number of times depending on the variable: zerothPos

The block movie clip appears once correctly when the function is called directly, but I don't want to call the function directly set I want the blocks to show up one after another instead of all at once.

I've tried this in both MX Flash 2004 and Flash 8 with the same results. Any advice would be appreciated.

Attached Code:
This topic is closed to new replies. Start a new post to keep the conversation going.
blemmoCorrect answer
Inspiring
June 7, 2006
Hi,

looks like a scope issue. Try the 2nd setInterval function, where you can pass the scope of the interval:
intervalID = setInterval(this,"addUnitBlocks",1000);

There's an issue with the attachMovie call: all attached clips will get the instance name "units", so each new clip should replace the clip attached before, resulting in only 1 clip on stage after the execution. There should be a counting var in the names, e.g.
this.attachMovie("block","units"+blcCnt, this.getNextHighestDepth(),{_x:20*blcCnt, _y:530});

cheers,
blemmo

3 replies

Participating Frequently
June 7, 2006
Oh, thank you so much. Your suggestion worked!

In this case having all of the clips have the same name is not a problem because I am not having the user do anything with them after they are displayed. They all get deleted at the same time anyways.

I have used your naming scheme in many other cases when I do need the user to drag clips indepently.

The syntax you gave me for the setInterval is what I needed. Thanks for your quick response.
Translate
Inspiring
June 7, 2006
Glad to help. I had to fight with a similar setInterval issue once, so I know it's hard to understand the scope thing if you never had this before.

greets,
blemmo
Translate
blemmoCorrect answer
Inspiring
June 7, 2006
Hi,

looks like a scope issue. Try the 2nd setInterval function, where you can pass the scope of the interval:
intervalID = setInterval(this,"addUnitBlocks",1000);

There's an issue with the attachMovie call: all attached clips will get the instance name "units", so each new clip should replace the clip attached before, resulting in only 1 clip on stage after the execution. There should be a counting var in the names, e.g.
this.attachMovie("block","units"+blcCnt, this.getNextHighestDepth(),{_x:20*blcCnt, _y:530});

cheers,
blemmo

Translate