Copy link to clipboard
Copied
Hi all,
I'm trying to help someone figure something out for a project they're working on.
They have a series of movieclips which they'll make invisible with the classic "this.movieclipname.visible=false" code. They have a button that's intended to reveal one movieclip at a time. Is it possible to set it so that the order in which the movieclips are revealed is totally randomized? So if someone was to play this in a browser several times they'd be seeing the movieclips in different orders as they click through each time?
Hope I'm explaining that clearly enough...
Thanks
D
Hi.
There several ways of achieving this interactivity. One way would be to store the Movie Clip instances in an Array, sort the array and then increment a variable to access each item of the array in each click. Like this:
var root = this;
var index = 0;
var mcs = [ root.yourMC0, root.yourMC1, root.yourMC2, root.yourMC3, root.yourMC4 ];
mcs.sort(function(){ return Math.random() - 0.5 });
mcs.forEach(function(mc){ mc.visible = false; });
root.yourRevealButton.on("click", function(){ mcs[Mat...
Copy link to clipboard
Copied
Hi.
There several ways of achieving this interactivity. One way would be to store the Movie Clip instances in an Array, sort the array and then increment a variable to access each item of the array in each click. Like this:
var root = this;
var index = 0;
var mcs = [ root.yourMC0, root.yourMC1, root.yourMC2, root.yourMC3, root.yourMC4 ];
mcs.sort(function(){ return Math.random() - 0.5 });
mcs.forEach(function(mc){ mc.visible = false; });
root.yourRevealButton.on("click", function(){ mcs[Math.min(index++, mcs.length - 1)].visible = true; });
I hope this helps.
Regards,
JC
Copy link to clipboard
Copied
Hi JC,
Would I then place that inside of a mouseclick event handler?
D
Copy link to clipboard
Copied
Nevermind. Figured it out! Thanks JC!
Copy link to clipboard
Copied
Awesome! You're welcome!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more