Jump to content
Search Community

Random order of animation

niklasinla test
Moderator Tag

Recommended Posts

Hi there!
I'm trying to wrap my head around making random animations out of nine mc's.
Trying to make a simple alpha animation that is random (within certain max - min duration) & also having a random order for which mc that is to be animated. Then also a stop of these animations after a set of time.
I don't really know how to do this.

Did some searching in the forums here but didn't find anything that I understand.

Anyone have some tips?

I'm in AS2.

 

Niklas

Link to comment
Share on other sites

Here is a tutorial for AS3 GSAP v11 that shows the basic approach

http://www.snorkl.tv/2011/09/actionscript-3-shuffle-array-and-loop-through-children/

 

 

I don't have time (at the moment) to convert that to AS2 GSAP v12, but I would recommend the following steps:

 

1: place all of your movie clips in an array

 

myMcs = [mc1, mc2, mc3, fred_mc]

 

2: shuffle the array (search google for shuffling AS2 array)

 

3: loop through the shuffled array of movie clips and create a tween for each movie clip with a random start time like Math.random()*3 which will ensure that each tween starts within 3 seconds.  

Link to comment
Share on other sites

here is the as2 code:

 


import com.greensock.*;
//create array
clips = [mc1, mc2, mc3, mc4, mc5];
//shuffle it
clips = shuffleArray(clips);


function shuffleArray(arr) {
var arr2:Array = [];
while (arr.length > 0) {
arr2.push(arr.splice(Math.round(Math.random() * (arr.length - 1)), 1)[0]);
}
return arr2;
}




//construct a timeline where each item animates from opacity 0 at a random time
var timeline = new TimelineLite();
for(i=0; i< clips.length; i++){
trace(clips[i]);
timeline.from(clips[i], 0.5, {_alpha:0}, Math.random()*3); 
}

see attached zip

 

randomEffects_CS5.zip

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...