patrickjv
August 9th, 2007, 04:43 PM
I have an MC which runs continuously with a addEventListener. At random moments it creates MC2s which need to fade away in a random duration. Imagine it like "waterdrops" which fade away.
I currently have them being generated at random moments with
function addchildobject(nr){
obj[nr] = new obj_pj_raindrops();
addChild(obj[nr]);
}
So far so good. Now I'm looking for best approach to fade them away. "waterdrops" also need to get a
- random duration fading away
- random scale
Idea I had
1) Have MC do all the work. -> Add an extra objvars[] array to every obj[x] e.g.
obj[x].objvars[1] = 1; // used as a counter
obj[x].objvars[2] = 20+Math.floor(Math.random()*20) // total duration to fade out
obj[x].objvars[3] = Math.random()*200 // random scale
"x" is a number increased every time a new "waterdrop" is generated.
Then use a obj[x].objvars[1]++ to increment counter and as soon as it reaches obj[x].objvars[2] remove it by;
if(obj[x]){
if(obj[x].parent != null){
removeChild(obj[x]);
}
}
And enclose/add a for() loop in addEventListener, fading away all "waterdrops" detected still pressent on stage.
Problem is, I can't manage to get an array added to the generated "waterdrops". I know I probably can predefine it in frame 1 of that MC2 but hope there's a way to add them on-the-fly.
2) I also know I probably can do the scripting within "waterdrop" itself but I didn't manage to make it remove itself when done.
Anybody any idea how to add an array within an child by array, in ohter words 'nest arrays'?
Or any other suggestion?
t.i.a.
P
I currently have them being generated at random moments with
function addchildobject(nr){
obj[nr] = new obj_pj_raindrops();
addChild(obj[nr]);
}
So far so good. Now I'm looking for best approach to fade them away. "waterdrops" also need to get a
- random duration fading away
- random scale
Idea I had
1) Have MC do all the work. -> Add an extra objvars[] array to every obj[x] e.g.
obj[x].objvars[1] = 1; // used as a counter
obj[x].objvars[2] = 20+Math.floor(Math.random()*20) // total duration to fade out
obj[x].objvars[3] = Math.random()*200 // random scale
"x" is a number increased every time a new "waterdrop" is generated.
Then use a obj[x].objvars[1]++ to increment counter and as soon as it reaches obj[x].objvars[2] remove it by;
if(obj[x]){
if(obj[x].parent != null){
removeChild(obj[x]);
}
}
And enclose/add a for() loop in addEventListener, fading away all "waterdrops" detected still pressent on stage.
Problem is, I can't manage to get an array added to the generated "waterdrops". I know I probably can predefine it in frame 1 of that MC2 but hope there's a way to add them on-the-fly.
2) I also know I probably can do the scripting within "waterdrop" itself but I didn't manage to make it remove itself when done.
Anybody any idea how to add an array within an child by array, in ohter words 'nest arrays'?
Or any other suggestion?
t.i.a.
P