Random placement of MC inside another MC, rather than on main timeline

Posted this in Flash 5 section, think it might be better off in here

good day flashers

I have a slightly tricky problem which I’m hoping you can help me with. I need to randomly position identical symbols in a movie - I have found a way I can do it in the main timeline using this code:
[COLOR=red]
n = 10;
while (n>0) {
duplicateMovieClip ("/r1", n, n);
n = n-1;
setProperty ("/symbol", _x, random(130));
setProperty ("/symbol", _y, random(148));
}
[/COLOR]
[U][COLOR=darkblue]RESULT[/COLOR][/U]
The problem is that the _x and _y parameters only seem to work in the main timeline, and I need the whole thing to be self-contained inside a movie clip, so that I can easily paste it into other Flash movies (about 75 of them). Is it possible to specify a random location inside a MC? I’d really appreciate any help or tips you can offer on this.

Thank you

Hello Denvish! Yes, this thread might be best placed here, so I deleted your post in the Flash 5 forum to reduce cluttering and duplicate threads. You are randomly placing the duplicated movie, correct? According to the code you have provided, you are naming the duplicated movies “n.” I think you may be targetting the wrong movie. Give this code a whirl:

n = 10;
while (n>0) {
duplicateMovieClip ("/r1", n, n);
setProperty ([COLOR=red]n [/COLOR] , _x, random(130));
setProperty ([COLOR=red]n [/COLOR] , _y, random(148));
n–;
}

I’m a bit fuzzy on what you are trying to accomplish, but I thought I’d take a stab at it. Also note I decremented the value “n” after the properties were set.

ah… oops…no, that was my mistake when I copied the code - it should have been:
[COLOR=red]
n = 10;
while (n>0) {
duplicateMovieClip ("/symbol", n, n);
n = n-1;
setProperty ("/symbol", _x, random(130));
setProperty ("/symbol", _y, random(148));
}[/COLOR]
where ‘symbol’ is the name of the MC I’m randomly placing

as you can see from [COLOR=darkblue]this .swf,[/COLOR] it does work - but what I want to be able to do is take the two levels from the main timeline, and incorporate them into a new movie clip symbol, so that I can easily paste them into other movies (I have built a small streaming music player - see music page [URL=http://denvish.com/pb/planetbob.htm][COLOR=blue]here[/COLOR] , and want to be able to add the effect (to the background) in each .fla file, in the easiest manner possible).

The other disadvantages of the duplicateMovie action are:

  1. All the duplicate movies seem to appear at the FRONT (ie top level) of the .swf, no matter which level they are placed on - I would like to be able to find a way round that. If the actions could be placed inside an MC rather than on the main timeline I think that would solve the problem.
  2. Each of the randomly-placed duplicated movies (10 of them, in the above code) appear in the same location each time they appear - so once each one has appeared once, it will always appear again in the same place (unless the page is refreshed). If possible, I would like each example to appear in a completely new position.

I realise I am asking a lot of you here, and probably confusing you with too much detail =) but I am keen to learn as much as I can about Flash, and in particular, Actionscripting; I’ve failed miserably in finding information about this problem anywhere else, so I really hope you can provide some pointers.

Have attached the .fla file - basically want to get the 2 layers from main timeline into a new MC, so I can bung it in any movie I wish

whew need a cuppa tea now :slight_smile:

thanks for the reply & code, RenaissanceGirl, and well spotted on the mistake :o but it doesn’t really solve my problem…

Or
to simplify the whole matter
how the hell do I specify a random location for a movie clip/graphic symbol inside another movie clip?
Having looked around, if I can do that, I can use attachMovie to achieve the rest

i don’t quite see how “/symbol” would refer to the duplicated clip…

but with attachMovie you needn’t worry about that since a happy thing about attachMovie is that the method returns a reference to the newly attached Movie. therefore:


function makeMoviesIn(target,movieToAttach){
   var mc,n = 10;
   while(n--){
      mc = target.attachMovie(movieToAttach,movieToAttach+n,n);
      mc._x = Math.random() * 130;
      mc._y = Math.random() * 148;
   }
}
// usage:
//  makeMoviesIn(_root.holderClip,"attachMe");

tnx 4 the response sbeener will try that once I’ve had some sleep. Looks like it should do the job.