Here is the problem.
In my Flash movie, each time a button is clicked, what should happen is that one movie clip is randomly selected from a collection of movie clips then displayed.
Eventually, the whole collection should be displayed.
What is actually happening is this:
Problem 1
The movie clips are being selected randomly but certain movie clips appear more than once (creating the effect of nothing happening on subsequent button presses when the number of a movie clip already on the stage is generated again).
Problem 2
The movie clips stop appearing altogether before the whole collection is displayed.
Problem 3
And most frustrating of all, there seems to be no connection between the variables in the code which represent the movie clips and the movie clips themselves.
The result of this is that through a trace function, it’s clear to see that the code is generating a separate pattern of random numbers completely unrelated to the movie clips that actually appear.
I tried to fix everything with the following code:
//This code goes into frame 1, layer 1.
select = new Array(1, 2, 3, 4, 5, 6, 7);
//This code goes into frame 2, layer 1.
stop();
//This code goes into the button on frame 2, layer 1.
on (press){
selected = select.splice( (random(select.length)) , 1);
trace (selected);
trace (select);
}
- //This code goes into frame 1, layer 1.
- select = new Array(1, 2, 3, 4, 5, 6, 7);
- //This code goes into frame 2, layer 1.
- stop();
- //This code goes into the button on frame 2, layer 1.
- on (press){
- selected = select.splice( (random(select.length)) , 1);
- trace (selected);
- trace (select);
- }
"Select" represents the array of movie clips. The variable "selected" represents the array elements from "select" which are spliced once they have been randomly picked. I thought if I spliced them out, they wouldn’t be picked again. The code works on it’s own in a test movie using the output window, but within the finished movie it doesn’t. I’d really appreciate a few pointers on this one because I’ve run out of ideas.
I'll send complete Flash files to anyone who wants them and can help. I use Flash MX 2004 version 7.0.
Many thanks.
mikeroesoft