Groups | Blog | Home
all groups > flash actionscript > march 2005 >

flash actionscript : Duplicating a movie clip and setting instaqnce name


adrianTNT
3/31/2005 11:14:38 PM
I have a clip and I want to duplicate it by "uplicateMovieClip".
When I do this I have to give ti a new instance name to new clip:
asd.uplicateMovieClip("asd2");

But I want part of the the instance name to be taken from a variable so the
instance name is dynamic, how can I do this?


//I have a clip asd, I want to duplicate it to create asd2
//asd.duplicateMovieClip("asd2");

counter = 2;
eval("asd.duplicateMovieClip(asd"+counter+")"); // here is the problem

asd2._x = 100;
asd2._y = 100;

Anyone can help me with this?
I know that the new instance name has to have " " next to it but how can I
insert that into the eval code?
-Adrian.
mandingo
3/31/2005 11:54:24 PM
Here, try this... this is code for a button (movieClip instance) that
duplicates a ball on the stage...

this.onRelease = function(){
counter++;
duplicateMovieClip(_root.ball,"ball"+counter,counter);
_root["ball"+counter]._x = _root.ball._x + (20*counter);
_root["ball"+counter]._y = _root.ball._y + (20*counter);
}

hope this helps,
cheers
mandingo
3/31/2005 11:59:08 PM
hang on ... I should have looked closer at what you had...

you are almost there... just complicating it a bit...

you had :

counter = 2;
eval("asd.duplicateMovieClip(asd"+counter+")"); // here is the problem

asd2._x = 100;
asd2._y = 100;

should be :

counter = 2;
asd.duplicateMovieClip("asd"+counter,counter);
asd2._x = 100;
asd2._y = 100;

that should work...
cheers,


adrianTNT
4/1/2005 12:21:23 AM
Thank you.
Now that I look at it it looks simple but for me it didn`t work because I had
some more complicated things there, I made more instances and I was trying to
make each one a duplicate of previous one when instead I could just duplicate
the first one and place them at different positions.
I think this was solved, now I am stuck at something else :)

Thanks.

mandingo
4/1/2005 12:45:26 AM
Well if you consider that each element needs to be on a unique depth (set by
counter variable), then just make the placement relative to the counter... like
what I showed with the ball example...

that places balls constantly offset by _x of 20 and _y of 20 based on the (20
* counter)

cheers,
adrianTNT
4/1/2005 1:56:31 AM
I am stuck at something else, can you tel me how to fix this?

products_loader.content.line1.product_logo.loadMovie(my_xml.firstChild.childNode
s[0].attributes.logo);

I thought it should be:

eval("products_loader.content.line"+my_counter+".product_logo.loadMovie(my_xml.f
irstChild.childNodes["+my_counter+"].attributes.logo)");

But it doesnt work.
line 1 has to be as the counter (line1,line2,line3) nad also the XML node
should change (childNodes[1],childNodes[2]...)

Can somone tell me how to fix it?
Thanks.
-Adrian.

adrianTNT
4/1/2005 2:11:45 AM
Cool, it works now, as always it looks simple and clear now.
I dont know why I didnt thought about ["line"+my_counter]

Thanks.
Jeckyl
4/1/2005 12:01:54 PM
you can only eval simple variable names .. not expressions like that

instead use

products_loader.content["line"+my_counter].product_logo.loadMovie(my_xml.firstChild.childNodes[my_counter].attributes.logo);
--
Jeckyl

Byron Canfield
4/3/2005 2:38:33 PM
It is not necessary to call the coordinates of the original from which the
duplicate was made -- the duplicate is, by definition, duplicated in the
exact same location as the original, so its coordinates already match.

this.onRelease = function(){
counter++;
rfcClip = duplicateMovieClip(_root.ball,"ball"+counter,counter);
rfcClip._x += 20*counter;
rfcClip._y = 20*counter;
}

--
--------
Reality will not be altered to comply with preconceived notions.

Byron "Barn" Canfield
Flash example files: http://www.canfieldstudios.com


[quoted text, click to view]

AddThis Social Bookmark Button