View Full Version : attachMovie does not attach!
javadi82
July 17th, 2003, 01:42 AM
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.
blah-de-blah
July 17th, 2003, 01:55 AM
wow you posted 3 topics at the same time....can i see the fla?
e.s.x.s
July 17th, 2003, 02:45 AM
for(i=0;i<5;i++){
balls=attachMovie("aball","b1"+i,i);
balls._x=100+i;
balls._y=100+i;
}
you must change it to:
balls.attachMovie("aball","b1"+i,i);
e.s.x.s
kode
July 17th, 2003, 03:06 AM
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... ;)
What I think, is that it's actually working, but you need to change these lines:
balls._x = 100+i;
balls._y = 100+i;
to:
balls._x = 100*i;
balls._y = 100*i;
=)
e.s.x.s
July 17th, 2003, 03:33 AM
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=100*i;
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=100*i;
balls["b1"+i]._y=100*i;
}
thx to kode for the idea..
e.s.x.s
kode
July 17th, 2003, 03:49 AM
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... ;)
attachMovie("aball", "b1"+i, i, {_x:100*i, _y:100*i});
e.s.x.s
July 17th, 2003, 03:58 AM
yeah,
the initObject keeps the code shorter and easier to understand ;)
javadi82
July 17th, 2003, 07:30 AM
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.
e.s.x.s
July 17th, 2003, 07:33 AM
exactly! .. ;)
javadi82
July 17th, 2003, 07:50 AM
then how does
balls=attachMovie() work, when attachMovie() does not return anything!
e.s.x.s
July 17th, 2003, 08:04 AM
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
kode
July 17th, 2003, 11:41 AM
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. :P
EDIT. I checked it again, MovieClip.attachMovie DOES return the MovieClip too.
javadi82
July 18th, 2003, 09:02 AM
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)?
kode
July 18th, 2003, 09:06 AM
trace(this.attachMovie("someID", "someInstance", someDepth));
You could contact them, I don't think they will change it though. :P
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.