13 Replies Latest reply on Sep 25, 2006 5:33 AM by Newsgroup_User

# duplicate attached moive clips-urgent

Hullo, all
here is a simple animation I wrote. 81 duplications of moive clip "ball"
appear on screen and form a rectangle shape. now the problem is all 81 balls appear and animate at the same time.

is it possible to make 5 duplications appear and form part of the rectangle shape every second?

import mx.transitions.Tween;
import mx.transitions.easing.*;
var intervalId:Number;
var count:Number = 0;
var maxCount:Number = 10;
var duration:Number = 1000;
for (i=0; i<10; i++) {
for (j=0; j<10; j++) {
var ball = this.attachMovie("ball", "ball", i+10*j);
var ball_x = Math.random()*Stage.width;
var ball_y = Math.random()*Stage.height;
var end_x = 40+i*30;
var end_y = 40+j*30;
var timing = Math.random()*5;
var ball_tween1:Object = new Tween(ball, "_x", Strong.easeOut, ball_x, end_x, timing, true);
var ball_tween2:Object = new Tween(ball, "_y", Strong.easeOut, ball_y, end_y, timing, true);
var ball_tween3:Object = new Tween(ball, "_width", Strong.easeOut, ball_x, 10, timing, true);
var ball_tween4:Object = new Tween(ball, "_height", Strong.easeOut, ball_x, 10, timing, true);
}
}

is there any flash guru can help me out?
• ###### 1. Re: duplicate attached moive clips
instead of use two for-loops, put the for-loop code in a function and call the function using setInterval().
• ###### 2. Re: duplicate attached moive clips
thanks, man. could you explain in detail? I am a newbie, so it will be helpful if you can type some code for me.
• ###### 3. Re: duplicate attached moive clips
it might have helped if i'd using the correct form of the verb "use". that should read:

instead of using two for-loops, put the for-loop code in a function and call the function using setInterval():

• ###### 4. Re: duplicate attached moive clips
wow! thank a lot. it helps. but i still wanna know if it's possible to random end_x a little bit, so make every 5 ball tween end at different point on the rectangle shape.

and when the animation ends, is it possible to make it start all over again after a few sec? do i need a timer?
• ###### 5. Re: duplicate attached moive clips
yes, you can add a random factor to end_x but then the balls will not align along a rectangular grid because those represent the _x parameter of tween's end point.

you can recycle this animation using:

• ###### 6. Re: duplicate attached moive clips
I studied the code. thank you for your removeMovieClip function!

Now the only problem left is the end x, y position. i tried to use 'for loop' and 'Math.random', but because there is a update every second, so the next random number might be the same as the previous one. so it causes some balls overlap.

Is there anyway to avoid the repeating random number after each update? Shall I create something like a two-dimensional array?
• ###### 7. Re: duplicate attached moive clips
what is it that you are trying to accomplish? are you trying to place the grid at random positions (instead of always having its upper left at 40,40) but still maintain the grid?
• ###### 8. duplicate attached moive clips-urgent
Thank you kglad, coldmine. I finally solved the problem with your great helps. I deeply appreciate that.
• ###### 9. Re: duplicate attached moive clips
quote:

Originally posted by: realifreebieIs there anyway to avoid the repeating random number after each update? Shall I create something like a two-dimensional array?

... sounds like a wonderful idea...
• ###### 10. Re: duplicate attached moive clips
hullo, I am a newbie, could you help me script it based on what i have done? it's school assignment, quite urgent.

any help will be appriciated.

thank you
• ###### 11. Re: duplicate attached moive clips
Here is the code for recording the _x and _y grid:
• ###### 12. duplicate attached moive clips-urgent
thank you. i figured out.
• ###### 13. Re: duplicate attached moive clips
If this is a school assignment, presumably you should be doing at least
*some* of the thinking and work yourself.

--
-------------------------------
Remove '_spamkiller_' to mail
-------------------------------