Disconnection between movie clips and random number variable

  • mikeroesoft
  • Newbie
  • Newbie
  • mikeroesoft
  • Posts: 6
  • Loc: London, England UK

Post 3+ Months Ago

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:


Code: [ 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);
    }
  1. //This code goes into frame 1, layer 1.
  2. select = new Array(1, 2, 3, 4, 5, 6, 7);
  3. //This code goes into frame 2, layer 1.
  4. stop();
  5. //This code goes into the button on frame 2, layer 1.
  6.     on (press){
  7.     selected = select.splice( (random(select.length)) , 1);
  8.     trace (selected);
  9.     trace (select);
  10.     }



"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
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • holyzombiejesus
  • Born
  • Born
  • holyzombiejesus
  • Posts: 1

Post 3+ Months Ago

Hey dude,

I've got pretty much exactly the same problem, and its a RIGHT B*I*T*C*H. I've been lookin for stuff on it for ages, and eventually found this:

http://iat.ubalt.edu/courses/idia610.185_Fa04/random.shtml

which is kinda useful for making sure certain things don't get selected twice in succession.

What I'm trying to make work, and don't seem to be getting much advice on at all :( is using an array like this

array0 = new Array(1.swf,2.swf,3.swf,4.swf,5.swf,6.swf,7.swf);
array1 = new Array(7.swf,6.swf,5.swf,4.swf,3.swf,2.swf,1.swf);
array2 = new Array(1.swf,3.swf,5.swf,7.swf,2.swf,4.swf,6.swf);
array3 = new Array(6.swf,2.swf,4.swf,7.swf,1.swf,3.swf,5.swf);
array4 = new Array(1.swf,7.swf,2.swf,6.swf,3.swf,5.swf,4.swf);
array5 = new Array(1.swf,5.swf,2.swf,4.swf,3.swf,7.swf,6.swf);


to mimic the random selection. The 'random' orders are the different elements in this here array thingamejigger (i have seven different movies to load, hence seven movies in different orders.) I'm thinking that if i put some script at the start of the movie to select AT RANDOM one of these orders, and abit of script at the end so it doesn't select the same order twice in a row, I'd be in business.

But Im tired. And it hurts to think. If i figure a way through it I'l let ya know, and any help you can swing my way would be appreciated :D


Cheers buddy,

HOLYZOMBIEJESUS
  • Lord Sivell
  • Novice
  • Novice
  • Lord Sivell
  • Posts: 32
  • Loc: Australia

Post 3+ Months Ago

Hey,

I got a random movie attaching like so:

Code: [ Select ]
// 1st frame - this array can be any length
select = new Array(0, 1, 2, 3);

// 2nd frame
stop();

// button, on 2nd frame
on (release) {
    randomNum = random(select.length);
    _root.attachMovie("movie_"+select[randomNum], "movie_"+select[randomNum], select[randomNum]);
    eval("_root.movie_"+select[randomNum])._x = random(400)+100;
    eval("_root.movie_"+select[randomNum])._y = random(250)+100;
    select.splice(randomNum, 1);
}

// in the libaray there are 4 movies:
// movie_0, movie_1 etc.
  1. // 1st frame - this array can be any length
  2. select = new Array(0, 1, 2, 3);
  3. // 2nd frame
  4. stop();
  5. // button, on 2nd frame
  6. on (release) {
  7.     randomNum = random(select.length);
  8.     _root.attachMovie("movie_"+select[randomNum], "movie_"+select[randomNum], select[randomNum]);
  9.     eval("_root.movie_"+select[randomNum])._x = random(400)+100;
  10.     eval("_root.movie_"+select[randomNum])._y = random(250)+100;
  11.     select.splice(randomNum, 1);
  12. }
  13. // in the libaray there are 4 movies:
  14. // movie_0, movie_1 etc.


I hope this helps, you can get the .fla at http://www.particlesystem.com/haydn/ref/random_attach.fla.

Sivell
  • mikeroesoft
  • Newbie
  • Newbie
  • mikeroesoft
  • Posts: 6
  • Loc: London, England UK

Post 3+ Months Ago

I've recently come back to a problem from a few months ago which I ran into while trying do something with random movie clips.

I left it here at Ozzu.com for a while and it's only now I've come back to it. I just read the useful responses people left.

Sorry I didn't get back to you earlier but much gratitude for your help.

mikeroesoft

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 10 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.