attachMovie does not attach!

This actionscript for “attaching” five balls refuses to work! Why?

for(i=0;i<5;i++){
balls=attachMovie(“aball”,“b1”+i,i);
balls._x=100+i;
balls._y=100+i;
}
Note:aball is the linkage name of the movieclip.

wow you posted 3 topics at the same time…can i see the fla?

for(i=0;i<5;i++){
[COLOR=red]balls=attachMovie(“aball”,“b1”+i,i);[/COLOR]
balls._x=100+i;
balls._y=100+i;
}

you must change it to:
[COLOR=red]balls.attachMovie(“aball”,“b1”+i,i);[/COLOR]

e.s.x.s

I don’t think that’s the problem, esxs. :-\

There are methods that return an Object, attachMovie returns the newly attached MovieClip (or any Symbol you attached). It’s like writing this[“b1”+i] so you understand… :wink:

What I think, is that it’s actually working, but you need to change these lines:
[AS]balls._x = 100+i;
balls._y = 100+i;[/AS]
to:
[AS]balls._x = 100i;
balls._y = 100
i;[/AS]
=)

balls=attachMovie(“aball”,“b1”+i,i);
if u run the code like above,it will don’t work.because the attachMovie method don’t has a property like that…

for(i=0;i<5;i++){
balls.attachMovie(“aball”,“b1”+i,i);
balls._x=100+i;
balls._y=100+i;
}
above code is true,but if u run this code u can’t see five balls definetely.because the balls are very close to each other…if u change the code to kode’s said:
for(i=0;i<5;i++){
balls.attachMovie(“aball”,“b1”+i,i);
balls._x=100i;
balls._y=100
i;
}
the result not changes, because u change the main MovieClip’s x and y coordinates. if you want to see the five balls exactly,u must change the code to:
for(i=0;i<5;i++){
balls.attachMovie(“aball”,“b1”+i,i);
balls[“b1”+i]._x=100i;
balls[“b1”+i]._y=100
i;
}

thx to kode for the idea…

e.s.x.s

That’s funny, I could swear that MovieClip.attachMovie returns an Object. Just tested it and you’re right. thanks. =)

BTW, if you want to make things even easier, you could take advantage of the initObject parameter… :wink:
[AS]attachMovie(“aball”, “b1”+i, i, {_x:100i, _y:100i});[/AS]

yeah,
the initObject keeps the code shorter and easier to understand :wink:

i checked with the explanation of attachMovie in the Help section of Flash MX and it said that attachMovie did not “return” anything.

proof:myMovieClip.attachMovie( idName, newName, depth [, initObject] )
Returns:Nothing.

exactly! … :wink:

then how does

balls=attachMovie() work, when attachMovie() does not return anything!

in your code “balls” is only gives you the
_level0.b11, _level0.b12, _level0.b13 …
but this isn’t means that the attachMovie() code runs correct.
and this is not what u want to do. u want to attach movies in the balls movieClip i think. With your code, u attach your movies into the _root movieClip…

e.s.x.s

Originally posted by javadi82
i checked with the explanation of attachMovie in the Help section of Flash MX and it said that attachMovie did not “return” anything.

It doesn’t say anything for MovieClip.createEmptyMovieClip either, althought this method does return the MovieClip created. :stuck_out_tongue:

EDIT. I checked it again, MovieClip.attachMovie DOES return the MovieClip too.

To kode:

Stupid question but anyway:How did you check that attachMovie returns an object.

More stupid question:Can we tell Macromedia to change the documentation(Flash help)?

[AS]trace(this.attachMovie(“someID”, “someInstance”, someDepth));[/AS]
You could contact them, I don’t think they will change it though. :stuck_out_tongue: