home   |   about   |   time   |   appearance   |   space   |   other   |   tips & tricks    

Randomized Time

In real life, part of the events we witness happen without our will and sometimes without us even anticipating them. In other words, we can't always tell when an action occurs, so in order to create realistic effects, we have to introduce this doubt in the movies. You may wonder when this becomes useful. Imagine the next effects:

» someone mumbling
» the blink of the human eye
» a lightning in the night's sky
» a falling star;
» a bird appearing in the landscape;

Knowing how to trigger events in flash randomly means knowing how often the action occurs. So you need to establish three things:
» the movie's Frame rate (click somewhere inside the Stage where there aren't any objects, open the Properties Panel and look in the right side of it)
» the action's length (in frames);
» the frequency (how many times the action takes place in a defined period of time)

Let's start with:

var ok, value, desiredValue:Number;
value = ...
desiredValue = ...
// the next sequence has to loop endless
// or until a condition is satisfied 
ok = random(value);
if( ok == desiredValue ) {
	// trigger action
}

After setting the Frame Rate think about the probability of the event to happen and decide on a "value": bigger number if you want it triggered rarely and smaller for an often occurrence. "desiredValue" is a number between zero and one less than "value". So the event happen whenever the randomly generated number ("ok") is equal to one of the numbers in the desired interval ("desiredValue"). You can use multiple values for "desiredValue" but instead, you can increase or decrease the "value" variable. Here are three examples of how you can play with these parameters, including two ways of creating the loops.