Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 12-09-2005, 02:45 PM   #1
Registered User
Join Date: Jul 2004
Posts: 10
Default Calling a random movie clip

Ok, I need to call a random movie clip out of say 10 clips to be displayed in a seqence every time the swf is loaded. Anybody got a script or tutorial? I'm new to this whole actionscript thing.
netfuel is offline   Reply With Quote
Old 12-09-2005, 10:41 PM   #2
I'm an alright guy
falltimemusic's Avatar
Join Date: Jun 2005
Location: I live where my rump rests
Posts: 292
Default two ways

you can do it the quick and dirty way or a more difficult way.

the easy way:

have each frame contain another MC.

then to randomly select, do this


//this assumes you have 5 different frames with different MCs.
//You can have as many as you like.
whatMC = random(5)+1;

the hard way (im only going to post the code if you ask for it) you would have to dynamically create a random MC out of the library. This could be useful in some cases, but probably wont really be necessary for what you are looking to do.
falltimemusic is offline   Reply With Quote
Old 01-03-2006, 06:32 PM   #3
Happy Mistakes
Suzaku7's Avatar
Join Date: Dec 2005
Posts: 18
Send a message via AIM to Suzaku7

HI I was using code just like your quick way and I was having trouble with once it was embedded into the html page it would not load and play thru and start the random script.
I was curious if you ran into this problem, and if so how did you solve it.
I woudl also be intrested in seeing the hard way you mentioned.
Suzaku7 is offline   Reply With Quote
Old 01-03-2006, 08:47 PM   #4
Registered User
Join Date: Oct 2005
Posts: 61
Send a message via AIM to Artech

The seperate frame solution is viable. However, there is another option that is similar in it's simplicity.

Say for example you have 10 MC's, named MC1, MC2... MC10.

You can access them by using brackets.

if you were to do this:
targetme = _root["MC" + (random(10) + 1)];
the variable targetme would then, basically, become a random one of those movieclips to which you can duplicate, delete, move, make invisible, whatever. In doing so it affects the origional movie clip.

Lets say the random(10) came out 5 (add 1 because random(10) is 0-9) and we typed
targetme._visible = false;
MC6 would then become invisible, or could be duplicated, or whatever you needed to do.

Artech is offline   Reply With Quote
Old 01-03-2006, 10:35 PM   #5
Happy Mistakes
Suzaku7's Avatar
Join Date: Dec 2005
Posts: 18
Send a message via AIM to Suzaku7

placement as always been hard for me to get for the code. Would that go in the same spot has the code I was already using?

cause yeah optimally I would want to be able to remove the movieclip that was called randomly until all were used then have it start all over again.
Suzaku7 is offline   Reply With Quote
Old 02-09-2006, 06:43 PM   #6
Registered User
Join Date: Feb 2006
Posts: 22

To set this up then, should this work?

_root["MC0"]._visible = false;
_root["MC1"]._visible = false;
_root["MC2"]._visible = false;
_root["MC3"]._visible = false;

targetme = _root["MC" + (random(4))];
targetme._visible = true;
coskier is offline   Reply With Quote
Old 02-09-2006, 10:14 PM   #7
Game On
sophistikat's Avatar
Join Date: Mar 2005
Location: Barrie, ON
Posts: 2,535
Default you can do this

ActionScript Code:
// create a list of our movieclips var mc_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];   // create shuffle function function shuffle() {     return Math.floor(Math.random() * 2); }   // shuffle our array mc_list.sort(shuffle);   // i don't get what you want to do afterwards // but the array got shuffled to something like 8, 9, 4, 2 ,10, 1, 3, 5, 7, 6 // the following attaches 10 movieclips named mymc1-10 in the random order var mc_length = mc_list.length; for (var i = 0; i < mc_length; i++) {     this.attachMovie("mymc" + mc_list[i], "mymc" + mc_list[i], i); }
EDIT: shuffle script comes from senocular.... i think
sophistikat is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Movie clip loops conduct Other Flash General Questions 3 03-31-2006 05:22 PM
Help breaking out of movie clip u6crash ActionScript 1.0 (and below) 2 12-02-2004 08:55 AM
movie clip size problem steveg ActionScript 1.0 (and below) 8 12-26-2001 02:55 PM
Masking in Movie Clip sanjubawa Animation and Effects 1 07-22-2001 08:56 AM
masking Movie Clip sanjubawa Other Flash General Questions 1 07-17-2001 05:50 AM

All times are GMT. The time now is 05:55 AM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.