Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Randomly Generate A Clip From An Array Of Clips



I am using Flash MX and am trying to have an MC randomly selected from another MC. The first MC simply has an instance name of container and I want to place code using onClipEvent(load) to randomly select a movie that is not on the stage but has linkage properties set to export. The problem is that I want the container clip to randomly select a clip from an array of movie clips called graphic[nm]. I'm having problems to get it to randomly generate with this condition. For example if I have 10 movie clips in the graphic mc array then I want the code placed on the container clip to randomly select a number between 0 and 9 - ie: between graphic[0] and graphic[9] where as stated above, none of the clips in the array are actually on the stage but are to be dynamically placed using the attachMovie method.

If any skilled coder could help me with this I would greatly appreciate it as I've been stumped on this for a while now. If possible could you please include an example of the actual code you would place on the onClipEvent(load) for the MC with instance name, container and also if it is possible, how to create the MC array named graphic[nm]. I'm not sure, perhaps it is only possible to randomly select one of the clips in the array if they are actually on the stage? Either way, I'm not sure how to go about creating this array.

Many thanks,
JN Hawkins



FlashKit > Flash Help > Flash ActionScript
Posted on: 12-28-2002, 06:50 PM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Randomly Generate A Clip From An Array Of Clips
I am using Flash MX and am trying to have an MC randomly selected from another MC. The first MC simply has an instance name of container and I want to place code using onClipEvent(load) to randomly select a movie that is not on the stage but has linkage properties set to export. The problem is that I want the container clip to randomly select a clip from an array of movie clips called graphic[nm]. I'm having problems to get it to randomly generate with this condition. For example if I have 10 movie clips in the graphic mc array then I want the code placed on the container clip to randomly select a number between 0 and 9 - ie: between graphic[0] and graphic[9] where as stated above, none of the clips in the array are actually on the stage but are to be dynamically placed using the attachMovie method.

If any skilled coder could help me with this I would greatly appreciate it as I've been stumped on this for a while now. If possible could you please include an example of the actual code you would place on the onClipEvent(load) for the MC with instance name, container and also if it is possible, how to create the MC array named graphic[nm]. I'm not sure, perhaps it is only possible to randomly select one of the clips in the array if they are actually on the stage? Either way, I'm not sure how to go about creating this array.

Many thanks,
JN Hawkins

Generate Images Randomly
hi,

i have a set of images(around 5) which need to movein randomly in a limited area (specific width and height).and this random generation can be for almost 30 secs with a gradual speed increase.how can i do this?

How To Randomly Generate Clouds?
Hi I would like to randomly generate clouds, so that they go across the screen. I was wandering if anyone could help me with some code? that i would put in the actionscript? or if anyone knew a tutorial that would help me with this problem as i cant seem to get it to work and not too sure how..

Thank you so much look forwards to hearing from you

BettyBoop

Randomly Generate Positive Numbers
I'm rotating a movie clip (a big circle) and want to pick a random number for the rotation position to stop at. I need to create only numbers that are multiples of 4. (I have the increment for rotating it at 1 -- and it's too slow)
--------------
HERE'S MY CODE

I created a random number on the root timeline:

// create random number to use for final position
var ranPos = Math.floor(Math.random()*360)


I've attached this to the mc:

onClipEvent (enterFrame) {
//create variables
turn = _rotation

//start rotation
_rotation = _rotation+1;

//stop rotation at random number
if (turn == _root.ranPos) {
_rotation = turn;
stop();
}
}

I'm a newbie with actionscript so let me know if this approach is totally boneheaded - THANKS

Randomly Generate Letters And Numbers?
Anyone know of a quick way to randomly degenerate a series of 8 letters and numbers?

AS 2 Randomly Generate 3 Unique Numbers
I need to generate 3 unique numbers that will allow me to call from an array that has a list of FLVs with links, title and maybe a description. I know how to make random numbers but i need to know how to make sure that they are not doubling up so i can have [1,8,0] but not [1,8,1]. i will attach all my files and let someone take a look and see if they understand what i am doing.

What i am trying to do is in the chooser.fla is randomly fill the empty movieClips and then i want to build in a timer that will refresh the movieClips with fresh images.

[MX04] Need To Randomly Generate One Of 5 Swf Files To Play
I have 5 small swf files sized to play in a particular table cell on the home page. I need a random generator script that will pick a different one of the 5 to play each time the page is reloaded.

I was hoping to be able to use a standard SSI Random Image Displayer like the one at: http://www.scriptarchive.com/ssi_image.html
But the script lists image URL's in a string separated by commas, so inserting the flash object tags there is not possible as far as I can tell.

Is there another script that might allow me to do this?

Randomly Generate In A Dynamic Text Field
Hello everyone! I am still having problems randomly generating some text in a dynamic text field box. I am new to flash 8 and I am struggling with the action script unless I have some guide to go by. But what I am trying to do is make numbers for ex. (1+1=, 2+2=, etc.) generate in a dynamic txt field at the click of a play button. I would greatly appreciate it if someone could help me.

Generate Random Value From Array 'excluding' The Current Array Value
getting my head round flash (sorta!)...

ok, nearly got this working; i have 11 movie clips on the root timeline and a empty controller movie. what i need to happen is for a random movie clip to play. when it reaches a point in it's own timeline, it sets the playNext variable to true and the controller movie clip works out the next random movie to play.

the problem comes when the controller 'randomly' picks the movie clip thats already playing! then the whole thing breaks...

is there a way that i can say 'generate me a random clip to play from this array 'excluding' the currently playing movie clip'?

any suggestions would be grand.

this is what i have on my controller clip:

onClipEvent (load) {
//define a new array
video_array = new Array();
//list each of the videos
video_array[0] = "zero";
video_array[1] = "one";
video_array[2] = "two";
video_array[3] = "three";
video_array[4] = "four";
video_array[5] = "five";
video_array[6] = "six";
video_array[7] = "seven";
video_array[8] = "eight";
video_array[9] = "nine";
video_array[10] = "ten";
//this is the count of how many elements (videos) are in your array
max = video_array.length;
//set the playNext to true
_root.playNext = true;
}
onClipEvent (enterFrame) {
//if playNext is true
if (_root.playNext) {
//generate a new random video to play
randomNumber = Math.floor(Math.random()*max);
//store the name
randomVideo = video_array[randomNumber];
//tell that video to play
_parent[randomVideo].gotoAndPlay(13);
//record the video we are playing
crntVideo = randomVideo;
//set playNext to false
_root.playNext = false;
}
}

Generate Random Value From Array 'excluding' The Current Array Value
getting my head round flash (sorta!)...

ok, nearly got this working; i have 11 movie clips on the root timeline and a empty controller movie. what i need to happen is for a random movie clip to play. when it reaches a point in it's own timeline, it sets the playNext variable to true and the controller movie clip works out the next random movie to play.

the problem comes when the controller 'randomly' picks the movie clip thats already playing! then the whole thing breaks...

is there a way that i can say 'generate me a random clip to play from this array 'excluding' the currently playing movie clip'?

any suggestions would be grand.

this is what i have on my controller clip:

onClipEvent (load) {
//define a new array
video_array = new Array();
//list each of the videos
video_array[0] = "zero";
video_array[1] = "one";
video_array[2] = "two";
video_array[3] = "three";
video_array[4] = "four";
video_array[5] = "five";
video_array[6] = "six";
video_array[7] = "seven";
video_array[8] = "eight";
video_array[9] = "nine";
video_array[10] = "ten";
//this is the count of how many elements (videos) are in your array
max = video_array.length;
//set the playNext to true
_root.playNext = true;
}
onClipEvent (enterFrame) {
//if playNext is true
if (_root.playNext) {
//generate a new random video to play
randomNumber = Math.floor(Math.random()*max);
//store the name
randomVideo = video_array[randomNumber];
//tell that video to play
_parent[randomVideo].gotoAndPlay(13);
//record the video we are playing
crntVideo = randomVideo;
//set playNext to false
_root.playNext = false;
}
}

Preloader For A Nav Clip That Loads Clips That Load Jpgs From An XML Array
Hey Folks,
I searched everywhere and tried everything I could find or think of and 3 days later I'm giving up.
I have a nav clip that is full of thumbnails for a gallery type thing. You can see it here:
http://blinkwavenyc.com/flas/interactive9.html

When I fill it with a ton of thumbs (later) it will take a while to fill and I would like a loader in the main window as there will be nothing there until the nav clip finishes loading.

The nav clip is dynamically loaded then populated with clips that in turn load the thumb jpgs from an XML file like this:


Code:
function buildNavigation() {
this.row = 0;
this.column = 0;
this.createEmptyMovieClip("navigation", 5);
navigation._x = navClipX;
navigation._y = navClipY;
//attach scroller to thumb clip
myScroller.scrollTarget = navigation;
// duplicate the navigation button.
for (i=0; i<paths.length; i++) {
navigation.attachMovie("baseThumb", "navBut"+i, i);
// set thumbnails to the correct place.
// place in rows & columns
navigation["navBut"+i]._x = this.tnBorder+(this.column*(this.tnSizeW+this.tnSpacing));
navigation["navBut"+i]._y = this.tnBorder+(this.row*(this.tnSizeH+this.tnSpacing+this.vertPad));
if (this.column<(this.maxColumns-1)) {
this.column++;
} else {
this.column = 0;
this.row++;
}
// load the thumb file
loadMovie(thumbs[i], navigation["navBut"+i].thumbImg);
}
trace(this.navigation.getBytesLoaded());
}
The problem is getting the bytesLoaded or bytes total for it as you can imagine.
I really need help badly. I'm tearing my hair out by the roots now. I put a chopped down version of the fla and xml and images in a zip file here:
http://www.blinkwavenyc.com/tests.zip
or if you need
http://www.blinkwavenyc.com/tests.exe
Thanks,
Erik

I parsed the XML like this:

Code:
var xmlfile:XML = new XML();
var rotatetime:Number = new Number();
var randomplay:String = new String();
var shownavigation:String = new String();
var transition:String = new String();
var paths:Array = new Array();
var thumbs:Array = new Array();
var links:Array = new Array();
// the parsing function.
xmlfile.onLoad = function(success) {
if (success) {
// get parameters from xml to variables.
// booleans are parsed as strings: can't get them
// to convert to booleans from xml .. :(
rotatetime = parseInt(this.firstChild.firstChild.childNodes[0].firstChild);
randomplay = String(this.firstChild.firstChild.childNodes[1].firstChild);
shownavigation = String(this.firstChild.firstChild.childNodes[2].firstChild);
transition = String(this.firstChild.firstChild.childNodes[3].firstChild);
// get paths and links from xml to array.
for (var i = 0; i<this.firstChild.childNodes[1].childNodes.length; i++) {
paths.push(this.firstChild.childNodes[1].childNodes[i].attributes.path);
thumbs.push(this.firstChild.childNodes[1].childNodes[i].attributes.thumb);
links.push(this.firstChild.childNodes[1].childNodes[i].attributes.link);
}
//trace(xmlfile.getBytesLoaded());
_root.attachMovie("loader_image", "loader_navigation", 14);
loader_navigation._x = imgClipX+((imgClipW-140)/2);
loader_navigation._y = imgClipY+((imgClipH-50)/2);
if (xmlfile.getBytesLoaded()<>xmlfile.getBytesTotal() or xmlfile.getBytesTotal() == 0 or xmlfile.getBytesTotal() == undefined) {
prog = Math.ceil(xmlfile.getBytesLoaded()/xmlfile.getBytesTotal()*11);
_root.loader_navigation.main.progres.gotoAndStop(prog);
} else {
_root.loader_navigation.main.progres.gotoAndStop(11);
_root.loader_navigation._visible = true;
}
// build navigation if necessary.
shownavigation == "true" ? buildNavigation() : null;
// get first random image if necessary.
randomplay == "true" ? nextImage=random(paths.length) : null;
// start first rotation.
rotateStepOne();
}
// xmlfile not needed anymore, so deleting it.
delete xmlfile;
};
//whitespace fix and actual load command.
xmlfile.ignoreWhite = true;
xmlfile.load(_root.file);
Thanks Again,
Erik
for some reason this forum refuses to display the actionscript so here it is without the "CODE" tags

function buildNavigation() {
this.row = 0;
this.column = 0;
this.createEmptyMovieClip("navigation", 5);
navigation._x = navClipX;
navigation._y = navClipY;
//attach scroller to thumb clip
myScroller.scrollTarget = navigation;
// duplicate the navigation button.
for (i=0; i<paths.length; i++) {
navigation.attachMovie("baseThumb", "navBut"+i, i);
// set thumbnails to the correct place.
// place in rows & columns
navigation["navBut"+i]._x = this.tnBorder+(this.column*(this.tnSizeW+this.tnSp acing));
navigation["navBut"+i]._y = this.tnBorder+(this.row*(this.tnSizeH+this.tnSpaci ng+this.vertPad));
if (this.column<(this.maxColumns-1)) {
this.column++;
} else {
this.column = 0;
this.row++;
}
// load the thumb file
loadMovie(thumbs[i], navigation["navBut"+i].thumbImg);
}
trace(this.navigation.getBytesLoaded());
}

Preloader For A Nav Clip That Loads Clips That Load Jpgs From An XML Array
Hey Folks,
I searched everywhere and tried everything I could find or think of and 3 days later I'm giving up.
I have a nav clip that is full of thumbnails for a gallery type thing. You can see it here:
http://blinkwavenyc.com/flas/interactive9.html

When I fill it with a ton of thumbs (later) it will take a while to fill and I would like a loader in the main window as there will be nothing there until the nav clip finishes loading.

The nav clip is dynamically loaded then populated with clips that in turn load the thumb jpgs from an XML file like this:

Code:
function buildNavigation() {
this.row = 0;
this.column = 0;
this.createEmptyMovieClip("navigation", 5);
navigation._x = navClipX;
navigation._y = navClipY;
//attach scroller to thumb clip
myScroller.scrollTarget = navigation;
// duplicate the navigation button.
for (i=0; i<paths.length; i++) {
navigation.attachMovie("baseThumb", "navBut"+i, i);
// set thumbnails to the correct place.
// place in rows & columns
navigation["navBut"+i]._x = this.tnBorder+(this.column*(this.tnSizeW+this.tnSpacing));
navigation["navBut"+i]._y = this.tnBorder+(this.row*(this.tnSizeH+this.tnSpacing+this.vertPad));
if (this.column<(this.maxColumns-1)) {
this.column++;
} else {
this.column = 0;
this.row++;
}
// load the thumb file
loadMovie(thumbs[i], navigation["navBut"+i].thumbImg);
}
trace(this.navigation.getBytesLoaded());
}
The problem is getting the bytesLoaded or bytes total for it as you can imagine.
I really need help badly. I'm tearing my hair out by the roots now. I put a chopped down version of the fla and xml and images in a zip file here:
http://www.blinkwavenyc.com/tests.zip (340k)
or if you need
http://www.blinkwavenyc.com/tests.exe
Thanks,
Erik

I parsed the XML like this:

Code:
var xmlfile:XML = new XML();
var rotatetime:Number = new Number();
var randomplay:String = new String();
var shownavigation:String = new String();
var transition:String = new String();
var paths:Array = new Array();
var thumbs:Array = new Array();
var links:Array = new Array();
// the parsing function.
xmlfile.onLoad = function(success) {
if (success) {
// get parameters from xml to variables.
// booleans are parsed as strings: can't get them
// to convert to booleans from xml .. :(
rotatetime = parseInt(this.firstChild.firstChild.childNodes[0].firstChild);
randomplay = String(this.firstChild.firstChild.childNodes[1].firstChild);
shownavigation = String(this.firstChild.firstChild.childNodes[2].firstChild);
transition = String(this.firstChild.firstChild.childNodes[3].firstChild);
// get paths and links from xml to array.
for (var i = 0; i<this.firstChild.childNodes[1].childNodes.length; i++) {
paths.push(this.firstChild.childNodes[1].childNodes[i].attributes.path);
thumbs.push(this.firstChild.childNodes[1].childNodes[i].attributes.thumb);
links.push(this.firstChild.childNodes[1].childNodes[i].attributes.link);
}
//trace(xmlfile.getBytesLoaded());
_root.attachMovie("loader_image", "loader_navigation", 14);
loader_navigation._x = imgClipX+((imgClipW-140)/2);
loader_navigation._y = imgClipY+((imgClipH-50)/2);
if (xmlfile.getBytesLoaded()<>xmlfile.getBytesTotal() or xmlfile.getBytesTotal() == 0 or xmlfile.getBytesTotal() == undefined) {
prog = Math.ceil(xmlfile.getBytesLoaded()/xmlfile.getBytesTotal()*11);
_root.loader_navigation.main.progres.gotoAndStop(prog);
} else {
_root.loader_navigation.main.progres.gotoAndStop(11);
_root.loader_navigation._visible = true;
}
// build navigation if necessary.
shownavigation == "true" ? buildNavigation() : null;
// get first random image if necessary.
randomplay == "true" ? nextImage=random(paths.length) : null;
// start first rotation.
rotateStepOne();
}
// xmlfile not needed anymore, so deleting it.
delete xmlfile;
};
//whitespace fix and actual load command.
xmlfile.ignoreWhite = true;
xmlfile.load(_root.file);
Thanks again,
Erik

AttachMovie - Looping Thru An Array To Attach 6 Movie Clips Into An Empty Clip
Heres my issue...

Im loading in 6 different external icon button images using an XML file into an movieclip. well now i dont want external images to load from an xml file, i want the images to be inside flash in the library. I gave them a linkage name and made an array of them called menuIcons.

how do i get my icon images to load into flash without loading external images from an xml file...

heres my code..


var xml:XML = new XML();
xml.ignoreWhite = true;

xml.onLoad = function()
{
var nodes = this.firstChild.childNodes;
numOfItem = nodes.length;
for (var i=0; i<numOfItem; i++)
{
menuIcons = ["healthySkin", "environMoist", "lowerSkin", "drySkin", "waterInfusion", "healthyCellular"];

var t = home.attachMovie("item", "item" + i, i + 1);
t.angle = i * ((Math.PI * 2)/numOfItem);t.onEnterFrame = mover;
t.nameClip = (nodes[i].attributes.nameClip);
t.content = (nodes[i].attributes.content);
t.icon.inner.loadMovie(nodes[i].attributes.image);t.icon.onRollOver = over;
t.icon.onRollOut = out;
t.icon.onRelease = released;
}
}

thanks

slalonde44

Random Array, Array Name Selected Randomly
Random Array, Array Name selected Randomly

Here is the code:

var RDNumber2x:Array = [2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36, 38,40];

var RDNumber3x:Array = [3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54 ,57,60];

var RDNumber4x:Array = [4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,7 2,76,80];

var RDNumber5x:Array = [5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85, 90,95,100];

var RDNumber6x:Array = [6,12,18,24,30,36,42,48,54,60,66,72,78,84,90,96,102 ,108,114,120];

var RDNumber7x:Array = [7,14,21,28,35,42,49,56,63,70,77,84,91,98,105,112,1 19,126,133,140];

var RDNumber8x:Array = [8,16,24,32,40,48,56,64,72,80,88,96,104,112,120,128 ,136,144,152,160];

var RDNumber9x:Array = [9,18,27,36,45,54,63,72,81,90,99,108,117,126,135,14 4,153,162,171,180];

var RDNumber10x:Array = [10,20,30,40,50,60,70,80,90,100,110,120,130,140,150 ,160,170,180,190,200];

var RArray:Array = ["RDNumber2x","RDNumber3x","RDNumber4x","RDNumber5x ","RDNumber6x","RDNumber7x","RDNumber8x","RDNumber 9x","RDNumber10x"];

var RArrayBox:String;
var RArrayBoxS = 0;


RArrayBox = RArray[Math.floor(Math.random() * RArray.length)];


RArrayBoxS = RArrayBox[Math.floor(Math.random() * RArrayBox.length)];


trace(RArrayBoxS);

Heres The error:

ReferenceError: Error #1069: Property 6 not found on String and there is no default value.
at randomarray_fla::MainTimeline/randomarray_fla::frame1()

What I am trying to atchieve is randomly selecting the array name and then randomly selecting something from that array.

So I am randomly selecting from a randomly selected array

Can anyone help with my problem?

Generate Empty Movie Clips W/ Scrollbar
Hi,

I'm looking to create an app where I can dynamically load images into it, and control them with a scrollbar. Take a look at this image if you don't understand what I mean:

http://www.ianarmstrong.com/1.jpg

What I'm looking for is some tutorials to give me ideas on how best to go about this. I'm getting the dynamic info from XML. I need to know how to generate the empty movie clips for all the images, then load the images and have the whole thing controlled with a scrollbar.

How To Make AS Generate Multiple Movie Clips According To External Inf
Hi
I'm trying to write a code whith which an user can add comments to a certain image areas. It contains two sections: one for user, who is the owner of a picture and can add and edit tags and another section for a guest who can only see comments.Pictures and comments are loaded into movie externally from server. Comments are stored in txt file, each picture has its own txt file, all comment parameters are written into that file with a little help on php.
Now, I havent quite got a clue how to make following:
´When guest is about to see the comments, His desired picture is loaded into movie and so are the information from the texfile (spot coordinates, size, text etc.). Now code should generate comment movieclips based on the info from txt. How to make flash ganarate right number of movie clips according to the amount on for exaple commentbox size, which are separated wiht commas in txt files.
i could manage to replace infomanaging with xml instead on txt files, it that helps.

Thank you.


Array To Generate From Pool Of Questions
ok, I am building a quiz that pulls data from six different topics. I want to randomly pull two questions out of five from each topic.

What is the best way to do this? Do I need an array for each topic and one array to pull that data into a master array?

Thanks for the help.

Dynamically Generate MC Name With Array Indices
Trying to generate mc thumbnails on a page. I have one mc and want to duplicate it like a gallery.

I would think this would work, but it's not...

for(var i = 0;i<thumbs.length();i++){
myMc[i].x = 25*i;
myMc[i].y = 30*i;
addChild(myMc[i]);
}

TypeError: Error #2007: Parameter child must be non-null.

Can someone help... Thanks

How Can I Generate An Array Of *exclusive* Random Numbers?
I have been trying to write some code that will produce a list of *exclusive* random numbers between 1 –10.

What seemed very easy has actually taxed me to death!

I have started by setting up a standard “for” loop to push random numbers (generated by Math.random() ) into an array. I then set up another “for loop” within the first to go through all the indexes in the holding array & if the number at that index was not = to the random number generated, push that number onto the end of the array to give an array of exclusive numbers. Problem I have, apart from the fact that the above is about as much good as a chocolate teapot, is how do I know how many times to loop the initial for loop – I can’t tell how long it will take to generate a list of totally exclusive random numbers. If I tell it to loop 10 times it might just come up with 5 exclusive numbers – 3,8,6,4,4,5,3,3,9,1 – only 8,6,5,9,1 all the rest are duplicated.

Any ideas or better ways to achieve this?

[F8] Generate Buttons Based On Array Content
Hi, I am trying to create a scrollable list of links.
-I have a scroller with deceleration I'd like to utilize. It updates it's length based on the content of a movieclip. This is taken care of.
-The links that show in this scroller depend on the content of my array. For example, an element in my array holds ["green","shirt","www.flashkit.com"] and I want to pull this text into a button. The amount of buttons showing depends on how many elements are present in the array. Each button generated will pull it's text and URL from the array. I have my arrays taken care of. I just need help generating the buttons and pulling the info from the array. Thanks in advance! Very much appreciated!

Generate Button, Attach Script, From Array?
Hello,
Does anyone have any helpful suggestions as how to A) generate a button and then b) attach script to it dynaimcally from an array?

Thanks,
Pete

Generate New Length, Iteration Or Array From Loop
Hi all,

Let me try to explain this as short as possible.

I have an XML file that looks like this


Code:

<links>
<link visible="true" name="foo" />
<link visible="false" name="bar" />
<link visible="true" name="blah" />
<link visible="false" name="rofl" />
</links>



let's say I set-up everything in my AS..

then I loop the links node

Code:


for (i=0;i<linksnode.length;i++) {
here I can call any attribute. works perfect
if (atrribute.visible == "true") {
here I call only childnodes that have visible true.also works good.
}
}



Is there a way to call the new length of the "only true" childnodes? So first the length was 4 and now it's 2
And new iteration? for example first was 0123 and now 01.

Thanks,

David

Playing Movie Clips Randomly
i'm wondering if anyone can help with what i'm sure is a relatively simple task:

i'm building a flash file with a number of small movie clips in it. i would like these clips to play randomly (so that there are little animations playing here and there)

i'm afraid i'm no expert with actionscript but i appreciate it'll require a bit of maths
alternatively if you can direct me in the direction of any tutorials that cover the subject i'd appreciate that

cheers
jonsi

Randomly Generating Movie Clips?
Hello!
I want to have a button, that when clicked, prompts 5 movie clips to randomly display a movie clip within them. The names of the clips are:
grey
red
purple
green
blue
the interior clips for the movies are grey_1, grey_2 , grey_3, grey_4 and grey_5. This format is followed for each of the following clips. Do I use arrays to do this or is there a much simpler way? Or should I attach Math.random to the button?

not really sure of what to do...
THANKS in advance!!!

Randomly Attaching Movie Clips
Hi,

I want to randomly import movie clips from a 'library.swf';
(all the mc's within this .swf are linked to be exported as
"01", "02", etc.)

The code at the moment looks like this;

1st frame;
placeHolder.loadMovie("library.swf");

2nd frame;
stop ();
// mc 01
placeHolder.attachMovie("01", "my1", 2);
placeHolder.my1._x = 8;
placeHolder.my1._y = 18;
placeHolder.my1._xscale = 100;
placeHolder.my1._yscale = 100;

What I want to do is to, instead of using "01", "02", etc.
placeHolder.attachMovie("01", "my1", 2);
and use an action to randomly import movies from "01" to "50".

Any help or comments will be greatly appreciated,

Thanks,

Lenny.

Randomly Generating Movie Clips, Etc.
Anyone here know how to randomly generate instances of a movie clip?

To elaborate further, in case that helps, here's what I'm doing:

1. I am trying to make a game where you shoot at targets (a 'target' movie clip with Linkage 'targetlink').
2. The targets randomly appear.

I am trying to use attachMovieClip to do this, and so far, absolutely nothing happens when I test the movie. Any clues?

Here's my script, if that helps anything:


PHP Code:




createTarget = function(factor, x, y) {
    var shootMe = this.attachMovie("targetlink", "Target", 0);
    // variables for expedited code execution
    var mr = Math.random, mf = Math.floor
    
    // put target at specific x and y on stage
    shootMe._x = x;
    if (shootMe._x>40 || shootMe._x<510) {
        shootMe._y = mf(mr()*400);
    } else {
        shootMe._y = y;
    }
    
    // set target's rotation
    target._rotation = mf(mr()*360)-180;
};
createTarget();







Now, I can get it to generate the movie clip at this point, at the correct random coordinates and stuff, BUT.......

it appears to be on a "layer" way above everything else in the movie. So my custom cursor can't target it, for one thing, and it is not clickable, meaning that the game is very boring (as there is nothing to do but look at a target).

How on earth do I get this thing on a more interactive level? Any ideas what I'm doing wrong?

Additionally, the cursor is supposed to turn red, etc. when over the movie clip, and I've got code for it that works, but how do I make sure this code is still applied once the instance is randomly generated?

Whew... anyone who can help me on this gets mucho thanks :)

Thanks a ton,
-wobbly

Play Randomly Movie Clips
i used this code...

Code:
random = Number(random(9))+1;
tellTarget ("/mc" add random)
gotoAndPlay(1);
}
then this one...

Code:
r=int(Math.random()*9)+1;
_root["mc"+r].gotoAndPlay(1);
}
im using 79 movieclips...they are tiny sqares but they all are different...

i need to play the animation that each square has (change color) without pressing any button...the first code worked pasting it into a button...but second one dindnt worked....

ah!...and with the first code...i can only play randomly the first 9 MC...and then comes and error of level_0

Playing Movie Clips Randomly
hi!

I have 8 movie clips on the main timeline (all clips just have some text that fades in and out). Is there a way of playing these clips in a random order? ie: clip1 plays, then clip5, then clip8, then clip3 and so on...

if anyone can help that would be grand!

thanx in advance

Movie Clips Randomly Selecting
Hello,

I wonder if someone can help me with this dilemma I have. Ok, I have 3 MC's in the Library which I already placed Links to it, in order to use the AttachMovie Method to call them, now, how can I placed them via Randomly on the screen using the AttachMovie Method? I've read that one can 'Load' random Movies(ex:swf's, jpeg's, sounds, ect..) via the LOADMOVIE command, however, I would like to load these MC's using the AttachMovie method randomly, is there a way to do this without using the LOADMOVIE? Also, I would like it to be a continuous loop....These 3 MC's would be placed on the background of the stage....I would appreciate ur help on this matter..........Thanks and God Bless....


www.ymisitio.com

Randomly Loading Movie Clips
Ok, Im going to try and attempt to explain this....

I want to make an MC (lets say we call it MC_main), that contain or loads other MC's (from a list of MC's in the library, lets say MC_A, MC_B, MC_C, MC_D......to M or something)...in a random sequence. How can I do this?


Thanks

Having Randomly Loaded Clips Match Up With Each Other
Heres the deal. I've found tutorials that show how to randomly load from a selection of movie clips. My problem is, I have two clips that load on top of each other. Ones a blurred image, the other is a clear, and when you move a mask over the image, it goes from blurry to clear. Right?

But I want a different image to load everytime. Problem is that I need both the random blurry and clear pictures to be the same! No point moving your mouse over a blurred picture of a mountain only to find a clear river underneath, right?

Playing Clips Randomly Within A Movie
I have a flash movie (made in flash mx) of a wall, within the wall there are other small movies such as one off a snail, a worm etc

What actions script could i use so these movie clips randomly play. i.e I want things to randomly happen like a worm pop out of the hole. I don't want it just to happen when the movie is first loaded. Hope this makes sense.

Movie Clips Loaded Randomly
Hi

My query relates to swopping one movie clip for another in a random fashion. I have a movie clip on my stage called "location" and when the movie loads I want the "location" movie to be replaced by any one of 3 slightly different movie clips called "canvas0", "canvas1", "canvas3" .

I have attached the following code to the "location" movie clip:

onClipEvent (load) {
choice = Math.round(Math.random()*3);
switch (choice) {
case 0 :
location.loadMovie("canvas0");
break;
case 1 :
location.loadMovie("canvas1");
break;
case 2 :
location.loadMovie("canvas2");
break;
}
}

I have the "canvas" movie clips in the library and their linkage is set to "Export with Actionscript". I am using Flash MX.

Does anyone have any idea on why the above doesn't work?
Thanks.

Newtoo

How Do You Load Movie Clips Randomly?
I've got these mc of characters walking around. I want to add them to my stage randomly with code so these 12 different movie clips seem to come and go as they please. I understand I may need a timer so I don't get to may loaded at one time? This is a bear. Any help or tutorials I can use? Thanks, sincerely frustrated, Keith.

[F8] Randomly Attached Movie Clips
Ok, I'm sure this has a simple solution, and I suspect it involves using an array, but I'm not sure...

What I'm trying to accomplish is to have a movie clip randomly seleted and attached to the main movie. I have the for loop which will randomly generate the numbers, and I'd like to have that result concatenated with "mcC1Exercise" for attaching, so it would be mcC1Exercise01, McC1Exercise12, and so on. Here is the code I have so far.


Code:
function newExercise():Void {

// this function randomly selects a number
function randRange(min:Number, max:Number):Number {
var randomNum:Number = Math.floor(Math.random()*(max-min+1))+min;
return randomNum;
}
for (var i = 0; i<10; i++) {
var nRand1:Number = randRange(1, 10);
}
}

function displayExercise():Void {
this.attachMovie("mcC1Exercise", "Exercise", this.getNextHighestDepth());

};


I've tried simply just adding the nRand1 to the end of "mcC1Exercise" but no movie loads. What should I do to make this work?

Thank you...

[CS3] Randomly Call Movie Clips
Hi, I'm fairly new to actionscript

I'm trying to call movie clips randomly into my main movie. Here's the deal:

I have my main timeline.

In my movie i have a Butterfly movie clip and a Ladybird movie clip. Each movie has it's own timeline.

What i'm wanting is to play the movie clips at random x and y positions in my movie, but also at random times.

The code i have so far is below:

var RandomButterfly = function (){
_root.Butterfly._y = random(150)+100;
_root.Butterfly._x = random (70)+75;
}

var intervalID = setInterval(RandomButterfly, 12900);

var RandomLadybird = function (){
_root.Ladybird._y = 250;
_root.Ladybird._x = random (50)+50;
}

var intervalID = setInterval (RandomLadybird, 16500);

This works for setting the random x and y positions, but it calls the movie clip at the same time meaning that i get butterfly, ladybird, butterfly, ladybird, which isn't what i want. I'd like it to be more random.

Is there a way to do this?

Randomly Attached Movie Clips
Ok, I'm sure this has a simple solution, and I suspect it involves using an array, but I'm not sure...

What I'm trying to accomplish is to have a movie clip randomly seleted and attached to the main movie. I have the for loop which will randomly generate the numbers, and I'd like to have that result concatenated with "mcC1Exercise" for attaching, so it would be mcC1Exercise01, McC1Exercise12, and so on. Here is the code I have so far.

I've tried simply just adding the nRand1 to the end of "mcC1Exercise" but no movie loads. What should I do to make this work?

Thank you..








Attach Code

unction newExercise():Void {

// this function randomly selects a number
function randRange(min:Number, max:Number):Number {
var randomNum:Number = Math.floor(Math.random()*(max-min+1))+min;
return randomNum;
}
for (var i = 0; i<10; i++) {
var nRand1:Number = randRange(1, 10);
}
}

function displayExercise():Void {
this.attachMovie("mcC1Exercise", "Exercise", this.getNextHighestDepth());

};

Using Array Randomly?
I am using an array for generating the _x positions of multiple duplicate MC's. I want the MC's to take their _x value randomly from the array but I want the MC's to only take a value that has not been used from the array. When I try and do this I seem to be using endless loops that don't work. Does anyone know a way to do this?

Thanks

e.g.

// x positon array

xpos = new Array();
for (i=0; i<20; i++) {
xp = i*20;
xpos.push(xp);
}

// duplication loop

ccount = 1; // clip counter var
while (ccount<20) {
_root.rantxt.duplicatemovieclip("graph"+ccount, ccount);

// x placement (cannot make this random and unique)
_root["graph"+ccount]._x = xpos[ccount];

ccount += 1;
}

Generate/destroy Movie Clip
not sure how to fix this

if i could get a piece of code that generated a movieclip
instance of the button it might help.
thought that if how the buttons operate & become
accessible were changed it might fix the problem.

suggestions?

---

was working on an application and ran into a bit of aproblem
my buttons wouldn't work properly. first i thought it was just
an issue of badly defined hit areas/states

but i believe its because the buttons are overlaping each other
and blocking one another. so when the top buttons becomes
invisible and inactive they block the bottom butttons and end
up not functioning properly

Playing Multiple Movie Clips Randomly
I created about a dozen very simple movie clips, and I would like to post them on a website so that they play randomly. I assume I would need to create one movie out of the dozen clips, then use some sort of action script to make it play the different clips at random. I came across some script on another message board, but I have no idea where to put it. I would really appreciate any ideas here!

Playing Multiple Movie Clips Randomly
I created about a dozen very simple movie clips, and I would like to post them on a website so that they play randomly. I assume I would need to create one movie out of the dozen clips, then use some sort of action script to make it play the different clips at random. I came across some script on another message board, but I have no idea where to put it. I would really appreciate any ideas here!

Randomly Choose & Load Movie Clips
Hi All -

I'm still new to Flash, so please forgive me if this is a repeat or remedial question!

I have a html page that has a swf movie on the header. This header movie clip has anywhere between 4 and 6 different embedded movie clips that it cycles through. What I would like to do is have it randomly start the movies, so that the first movie in the movie clip isn't the first one to start everytime the html page is loaded. Is there an action script that will let me randomly load the movie clips?

Any help would be appreciated and please let me know if I can clarify if my question does not make sense. Thanks!

[F8] Displaying Movie Clips Randomly In Flash
Hi,
I have a question regarding flash.
My project scenario is, I have total no of 60 movie clips (Quick time) and are about to take 4 to 5 minutes each, my aim is to display 20 movie clips randomly at a time on the screen.
i.e., if we click on a button for the first time, it should display a 20 movie clips on the screen and when we click for the second time it should display other set of 20 clips, it may or may not repeat the previous ones. It means for every person it should be displayed with a different set of movie clips, no two persons can get the same set of movies. The movies should be randomly selected.
Could you please tell me what i need to do. and i was new to the action scripting. can you please write the script for this.
Thank you for your precious time.

[CS3] Tween Randomly Scattered Movie Clips
I'm making a puzzle and I have the full image displayed for a few seconds before the pieces scatter randomly. I'm using this code to scatter the pieces when the time line gets to that frame:


Code:
piece1._x = Math.floor(Math.random()*1024);
piece1._y = Math.floor(Math.random()*700);
piece2._x = Math.floor(Math.random()*1024);
piece2._y = Math.floor(Math.random()*700);
piece3._x = Math.floor(Math.random()*1024);
piece3._y = Math.floor(Math.random()*700);
piece4._x = Math.floor(Math.random()*1024);
piece4._y = Math.floor(Math.random()*700);

... Up to 20 pieces.

My problem is trying to get the pieces to slide to their random spots rather than just appear there. I've tried a few things and searched everywhere but I can't get it to work.

Here's the code I was trying to make it work with:

Code:
import mx.transitions.Tween;

import mx.transitions.easing.*;

Tween = new Tween(piece1, "_x", Bounce.easeOut, 100, 0, 3, true);
Tween = new Tween(piece1, "_y", Bounce.easeOut, 0, 100, 5, true);


Thanks in advance.

Placing Multiple Movie Clips Randomly
ok, lets see if i can describe what im wondering.

im making this flash game (sort of a matching pairs type thing). there are 75 characters to match. they are lined up in rows ( i think like 15 per row).

what i was trying to figure out was how to randomly position these characters, so they arent always in the same position when the page is refreshed. im having a hard time figuring this out because there are 75 different locations that characters can be placed, and after a location is filled i need to make sure another character doesnt go there......and it all has to be randomized.

does that make sense? any ideas?

Multiple Movie Clips Randomly Appearing
I am trying to create something in which a movieclip tweens across the screen horizontally, once spacebar is clicked. In a certain interval i want the same movieclip to be duplicated, but on a different position on the yaxis, and then to tween across. I want this to happen for upwards of 150 or so times.
Thanks.

Place 4 Clips In Stage 4 Positions Randomly
Hi!

Anybody knows how to place 4 images or 4 objects (clips, etc...) in 4 stage positions randomly? For example:

On event, onLoad or on btn press:

-First object coordenates _x = 100
_y = 100
-Second object coordenates _x = 300
_y = 100
-Third object coordenatess _x = 100
_y =300
-Forth object coordenates _x = 300
_y = 300

And each time we load or when press a btn I need to load the four objects randomly in this different positions of the stage. I need your help! (Sorry for my poor English)

Actionscript - Randomly Loading Movie Clips - PLEASE HELP
Hi,

I am trying to create a side banner Flash graphic on my website that randomly loads (one of 15 different) movie clips. Then, I need the clips to play back to back in random order - sort of like a non-interactive randomized image veiwer that plays while the end user veiws the webpage. Can anyone help me with the code? I am an actionscript novice, so I'm not sure how to approach this problem. Is it more efficient to load movie clips from the library, or an external folder?

Also, the clips are images that fade in and out (alpha) - one image per movie clip. How can I code these movie clips so that they fade in for 45 seconds, stay for 20 seconds, and fade out for 15 seconds?

I would appriciate any help...
Thanks,
-Ena

MX 2004 - Randomly Loading Movie Clips (help Meh)
I need to make something that mimicks The Dancer over at http://www.globz.com

I've created all the movie clips
but I don't know where to start with the loading and unloading of the dancing bits

The buttons at the bottom scroll through movie clips with different movement. So the "arms" button would load arms01, then when it's clicked again, it would load arms02, clicked again it would load arms03, and then repeat when it reached the end

Can anyone help me with the actionscript that would reside on each button?

Copyright © 2005-08 www.BigResource.com, All rights reserved