In the previous example, we rolled dice. We know that dice have six sides and we used the constant 6 in the code.
In this example we will add a flower movie clip to the stage when we click and then selecvt a random frame from the flower movie clip.


grass.addEventListener(MouseEvent.CLICK,clickGrass);
function clickGrass(e:MouseEvent): void {
var flwr: Flower=new Flower(); //create a new instance of the Flower
flwr.x=e.localX; //same place you clicked on the grass
flwr.y=e.localY;
var n:int=int(Math.random()*flwr.totalFrames)+1; //random frame
flwr.gotoAndStop(n); //stop at that frame
grass.addChild(flwr); //add the new flower to the grass
}
Note: You can add more frames. The code will work no matter how many frames you have in the flower.
Experiment: Add a tree to the picture. Create leaf with various sizes and shades of green. Add them to the tree when you click.
Download the movie to experiment.