I want them to appear on screen AT RANDOM. But each MC has to appear just one time. If all 12 have appeared (each time you start the application, the appearance is in a different order), the appearance have to stop and the application has to go to another frame.
How do I need to this?
Someone told me to use attachmovie method and using arrays. Something with this:
clips = [“MC1”, “MC2”, “MC3” … “MC12”]
randMC = clips.splice(random(clips.length),1);
if (clips.length){
randMC = clips.splice(random(clips.length),1);
}
Can someone help me with this and give me the exact script for this?
No problem… Don’t take it personally…
Please don’t post it over the forums… You just wasted either mine or pinkaboo’s time for this… I wouldn’t have posted what I have if I knew that pinkaboo was helping you… Know what I mean???
I don’t know how you have set things up in your Flash movie, so I just have it print out the possible random movieclip names… You need to use that data or the data that pinkaboo provided to fit your movie… All me or pinkaboo provided is the way to create an array which is one unique sets of random movieclip name which you can use in your movie…
I tried your way and I get the output screen. The random function is really working. No i’m trying to get the MC’s on stage, which have to be at random. I only don’t get further than the output screen…
Pinkaboo’s code als works fine and I also get the MC’s onscreen. So I need to combine some of his code with yours. I understand your code more than his code… but i’m still learning :bandit:
I used Pinkaboo’s actionscript to load the MC’s at random. Works fine, when I use the script on the main stage.
The MC’s which appear, appear al over the place on screen. So I want them to be loaded in a frame/border. I want them to load in a other MovieClip, and that movieclip I’ll put on the mainscreen. The MC’s will load within that movieclip, and not elsewhere on stage (I think…).
But when I try to do this, nothing happend. The output screen now doesn’t show the different MC’s names as it supposed to be. Instead the text ‘undefined’ showed up.
Do you know what this means? I think the ‘link’ to the instancename of the MC’s aren’t right anymoren. (when I delete the movieclips from my library, I got the same text in my output screen)
//randomly shuffles array and returns as custom defined new array
Array.prototype.shuffle = function(secondArray) {
interimArray = new Array();
arrayCount = ((this).length);
deleteCount = ((secondArray).length);
secondArray.splice(0, deleteCount);
//copies values from original array into interim array so that original data is not lost
for (a=0; a<arrayCount; a++) {
value = this[a];
interimArray.splice(a, 0, value);
}
//chooses random array data * copies into first postition in new array,
// deletes that data from interim array so it can’t be chosen again
for (a=0; a<arrayCount; a++) {
num = (random(interimArray.length));
value = interimArray[num];
secondArray.splice(1, 0, value);
interimArray.splice(num, 1);
}
};
//sample array to shuffle
i = 0;
_root.onMouseDown = function() {
//checks to see if i isn’t higher than the length of the array
if (i<mashremix.length) {
//if it isn’t utilises i to take that linkage name and attach the appropriate mc
_root.attachMovie(mashremix*,“newName”,depth);
trace("attach_or_whatever_to_add: "+mashremix*);
//increments i
i++;
//else, if i is the same as the length of the array, perform an action:
} else {
trace(“action_to_go_to_next_frame_here”);
}
};
It works fine if I paste this code in de actionscript area of a frame.
But when I put this code in a MovieClip, it doens’t work… and get “undefined” as message in my output screen.
Well… I just tried the code in my machine and that didn’t work for me… There were several errors in there… Maybe something happened while you were pasting it???
Anyways… Yes… The code is supposed to be run as a frame script, not the movieclip script… Why do you need to put the code into the movieclip??? When you say
But when I put this code in a MovieClip, it doens’t work…
Are you talking about the movieclip script or the frame script inside of the movieclip??? (Huge difference in between two…)
I think this should be done first… Me or pinkaboo provided you a code so that you can disect the code and understand it so that you can break it apart and reassemble it to your liking… What do you think??? Do you think you did that, or are you just copying it and pasting it hoping that the code will do the job for you???
The code as is stands like above, is the right code. When I paste it back in Flash, it works fine.
I meant a frame script. When I put it in a frame script, say, just after opening a new untitled flash file, (and copy the necessary MC’s: lbrboven, ldrboven, etc in the library) it works.
When I make a draw a square or something, convert that to a MovieClip, edit it, and in the first frame pasting the script… then the script doens’t work as it supposed to be. I got that ‘undefined’ error.
The reason why I want it in a MovieClip (that square, which doens’t take whole the stage/screen) is, that when I don’t use a MovieClip and just put the script in the framescreen of the ‘mainstage’, the MovieClips which appear at random by the script, appear all over the place. The first somewhere left in corner, the other somewhere else. You know what I mean?
By putting it in a MovieClip, I want the appearance restricted to the size of that MovieClip. As like a window, within the other movieclips (by the script) are being loaded in.
The code you and pink gave me, has two reasons for me. I’m a beginner, so I’m looking for a piece of code with some functions I need. By myself I never can program that code. I need examples. I will learn from that code.
This is the code. I just copied and pasted from my flash file. (and tested it,… it works)
//randomly shuffles array and returns as custom defined new array
Array.prototype.shuffle = function(secondArray) {
interimArray = new Array();
arrayCount = ((this).length);
deleteCount = ((secondArray).length);
secondArray.splice(0, deleteCount);
//copies values from original array into interim array so that original data is not lost
for (a=0; a<arrayCount; a++) {
value = this[a];
interimArray.splice(a, 0, value);
}
//chooses random array data * copies into first postition in new array,
// deletes that data from interim array so it can’t be chosen again
for (a=0; a<arrayCount; a++) {
num = (random(interimArray.length));
value = interimArray[num];
secondArray.splice(1, 0, value);
interimArray.splice(num, 1);
}
};
//sample array to shuffle
i = 0;
_root.onMouseDown = function() {
//checks to see if i isn’t higher than the length of the array
if (i<mashremix.length) {
//if it isn’t utilises i to take that linkage name and attach the appropriate mc
_root.attachMovie(mashremix*,“newName”,depth);
trace("attach_or_whatever_to_add: "+mashremix*);
//increments i
i++;
//else, if i is the same as the length of the array, perform an action:
} else {
trace(“action_to_go_to_next_frame_here”);
}
};
The code still is not working, so I had to run down to ActionScript.org to get the code from the thread…
Mainly the reason why the code didn’t work within the movieclip is because of the use of ‘_root’… Check out the pathing tutorials/section to get more information regarding it…
//randomly shuffles array and returns as custom defined new array
Array.prototype.shuffle = function(secondArray)
{
interimArray = new Array();
arrayCount = ((this).length);
deleteCount = ((secondArray).length);
secondArray.splice(0, deleteCount);
//copies values from original array into interim array so that original data is not lost
for (a = 0; a < arrayCount; a++)
{
value = this[a];
interimArray.splice(a, 0, value);
}
//chooses random array data * copies into first postition in new array,
// deletes that data from interim array so it can't be chosen again
for (a = 0; a < arrayCount; a++)
{
num = (random(interimArray.length));
value = interimArray[num];
secondArray.splice(1, 0, value);
interimArray.splice(num, 1);
}
};
//sample array to shuffle
mymashArray = ["boiled", "chipped", "fried", "bubbled", "sliced", "mashed", "baked", "roasted"];
//eg:
mymashArray.shuffle(mashremix = new Array());
trace(mashremix);
i = 0;
_root.onMouseDown = function()
{
//checks to see if i isn't higher than the length of the array
if (i < mashremix.length)
{
//if it isn't utilises i to take that linkage name and attach the appropriate mc
_root.attachMovie(mashremix*, "newName", depth);
trace("attach_or_whatever_to_add: " + mashremix*);
//increments i
i++;
//else, if i is the same as the length of the array, perform an action:
}
else
{
trace("action_to_go_to_next_frame_here");
}
};
I tested this on my machine and it works just fine… Let me know… Please use code formatting next time when you post the code…