PDA

View Full Version : I can't use the function "add" in a relative path


Artanist
08-07-2006, 12:52 AM
Hello guys, I'm new to this forum and I'm trying to learn the actionscript via youre great tutorials. Sorry if my english is bad, it just that I am from Quebec and it's a french province of Canada (the only one too thought ...).

So my problem is that I'm trying to duplicate a MC via a button and make them start at the frame number 2 when they appear. So I use a variable named "count" to make multiple duplication, but they only appear at the frame one even thought I use a relative path.

on(release) {
count = count + 1;
setProperty("Box",_alpha,50);
duplicateMovieClip("Box","Box" add count, count);
setProperty("Box" add count,_x,random(400));
setProperty("Box" add count,_y,random(400));
setProperty("Box" add count,_xscale,random(100));
setProperty("Box" add count,_yscale,random(100));
_level0.Box add count.gotoAndPlay(2)
}

My path work perfectly, because I try this code "_level0.Box1.gotoAndPlay(2)" and it worked with the first dupplication. So my question is, is it possible to make a path with an instance name who is generate with a variable linked with a concatenation value ?

Thank you for answering and I hope you understand me even if I'm not perfectly bilingual.

Cota
08-07-2006, 02:55 AM
duplicateMovieClip("Box","Box" + count, count);

Replace add with "+"

pixelwit
08-07-2006, 04:19 AM
You can either advance your ActionScripting skills light years ahead by using "Array Notation" or you can read up on the "eval" function.

Array Notation will help prepare you for Object Oriented Programming (OOP) and is THE most commonly used method. It looks like this:_level0["Box" add count].gotoAndPlay(2);

The Eval function may be deprecated (no longer recommended) but may better suit the way you code for the time being.

And as Cota said, you should probably replace the string operator "add" with the generic operator "+".

-PiXELWiT
http://www.pixelwit.com

Cota
08-07-2006, 04:20 AM
haha..didnt even see the path call...nice catch pixelwit..

pixelwit
08-07-2006, 04:24 AM
It happens sometimes.

-PiXELWiT
http://www.pixelwit.com

Artanist
08-07-2006, 06:43 PM
Thx for the help, but it didn't work :( I truly wounder why, you're cotations should've solve the problem ... Can I send you the fla by email ?

Artanist
08-07-2006, 06:44 PM
Thx for the help, but it didn't work :( I truly wounder why, you're cotations should've solve the problem ... Can I send you the fla by email ?

tg
08-07-2006, 09:30 PM
it looks like you may have a path problem where you are duplicating the movieclip, and setting its properties.

you may need to scope the 'box' object(like you did in your last line) in all lines of code ( duplicatte movie clip and setting the properties).

Artanist
08-09-2006, 02:22 AM
What do you mean by that ?