0
votes

I'm making a simple flash shooting gallery animation with about 5 targets on screen but I am useless at action script.

I have the main scene and 5 Target movie clips in an array. I would like to... -> Start Animation -> load random clip -> play random clip till end-> generate new random clip -> Repeat with Delay Offset....

So far I have the following:

function getRandomLabel():String {
var labels:Array = new Array("Tar1", "Tar2", "Tar3", "Tar4", "Tar5");

var index:Number = Math.floor(Math.random() * labels.length);
return labels[index];
}
this.gotoAndStop(getRandomLabel());
}

This is working... but I would like to add a delay and no repeat to this...

1
The specific technical problem you are having is unclear. Could be anything from don't know how to play a MovieClip to don't know what algorithm is.Organis
please look againDamian Shine

1 Answers

2
votes

Ok, lets do it.

// If you need to avoid playing the same movie two times.
var lastLabel:*;

// The list of labels.
var Labels:Array = ["Tar1", "Tar2", "Tar3", "Tar4", "Tar5"];

function playRandom():*
{
    do
    {
        // Get a random index.
        var anIndex:int = Math.random() * Labels.length;
    }
    while (Labels[anIndex] == currentLabel);

    // Keep the current label in the variable.
    currentLabel = Labels[anIndex];
    gotoAndStop(currentlabel);
}

function playNext():void
{
    // 1000 milliseconds = 1 second delay.
    setInterval(playRandom, 1000);
}

Then. At the end of each of your movie clips you need to correctly call the playNext method. If these movies are in the same timeline, as the code above, just call playNext(); If they are separate MovieClip objects, it will probably be (parent as MovieClip).playNext(); I cannot really tell because I don't know the structure of your movie. You will probably need to read the following to understand: http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e3e.html