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




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;
}
}



KirupaForum > Flash > Flash 8 (and earlier) > Flash MX 2004
Posted on: 03-14-2005, 08:25 AM


View Complete Forum Thread with Replies

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

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;
}
}

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?

Pls Help: Need To Create New Array Taking 3 Random Entries From An Existing Array
Hello

I have a 2d array:

qTeeth[1] = [How many teeth do we have?, 1-10, 11-20, 21-30, 11-20]
etc.

It goes [question, option1, option2, option3, real answer]

I now just want to extract 3 or so of these entries and create a new array with them. Since I want to just use 3 or so questions randomly from a large array of questions.

Does anyone know a good tidy script to do this with??


Thanks in advance,
Ben.

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?

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

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

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

[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

Using Random, BUT Excluding 0?
I'm loading a random .jpg. All works well, but I don't have a 0.jpg. Other code within the file will not permit me to create a 0.jpg. Can I exclude the number 0 somehow?

Here's what I'm using for my random code:

Code:
numOfImgFiles = 10;
LoadRandomJPG = function () {
var Rand = Math.round(Math.random() * numOfImgFiles);
container.loadMovie(("_images/" + Rand) + ".jpg");
delete this.onEnterFrame;
};
container.onEnterFrame = LoadRandomJPG;
Thanks for any ideas

Random Function Excluding Zero
hi there!

T1ger once posted a random function, and it goes like this:


Code:
function rand(min, max) {

return(random(max-min+1)+min);

}
what's the best way to use this excellent function, and exclude a certain number?
In my case I want min= -3 and max= 3, but I don't want to achieve zero.

thanx in advance!

How Do You Display The Current Array Element In A Text Box?
Hi guys - if I've got a text box called TextBox, an array called MyArray, and elements in the array called ("element1", "element2", "element3"...), how do I display in the text box what the current array element is?

//Displays the whole array:
TextBox1.text=""
for(i=0;i<MyArray.length;i++){
TextBox1.text+=MyArray[i] + ", ";

The code above displays the whole array, but I just want the current one - actually the current and the next element to display in the textbox. How do I do that?

Displaying Current Array Element's [i] Position
Hi guys - I've got the following code, which displays the current array element in a text box called 'CurrentElement', which I had previously used on the play button for an mp3 player I made:

CurrentElement.text=""
for(i=0;i<MyArray.length-1;i++){
CurrentElement.text =MyArray[i+1];
}

What I'd like to do is be able to insert something like it somewhere into this:

PlayArray.loadSound(MyArray[(now++)%MyArray.length]);
PlayArray.start();
PlayArray.onSoundComplete = function () {
if (now == MyArray.length) {PlayArray.stop();}else {
PlayArray.loadSound(MyArray[(now++)%MyArray.length]);
PlayArray.start();
}
}

The code I use to play mp3s in an array

What I'd like is for it to not display the array element - but the [i] number - the numeric place inside the array in which the current element resides - and I'd like for it to update every time the onSoundComplete cycles because there are still mp3s in the array to finish playing before coming to: "PlayArray.stop();" , so what ever code is used it will probably have to be in the first part of the play code and inside the onSoundComplete function

I'm just not sure how to word it all.

Current Frame Of A Movie Clip Within An Array
How can i get the _currentframe of a movieclip within an array?

(in making a battleships game)
I have two arrays (OpponentGrid and PlayerGrid) with 100 elements in each.

ActionScript Code:
OpponentGrid = new Array(o0,o1,o2,o3,o4,o5,o6,o7,o8,o9,o10...
PlayerGrid = new Array(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10...

I'm currently focusing on OpponentGrid and hope that it's solution will fix the other.

each of the movieclips inside are instances of the same movie clip.
Frame 1 => untested (with fire button) - shown if it is the players turn
Frame 2 => Hit
Frame 3 => Missed
Frame 4 => untested (without fire button) -shown if it is not the players turn

I need to loop through this array to update the grid dependant on a string:
0 = untested
1 = hit
2 = missed

My current code:


ActionScript Code:
for(i=0; i<100; i++){
    var temp:Number = _global.pGrid.charAt(i);
    _root.PlayerGrid[i].gotoAndStop(temp+1);
   
    switch(_global.oGrid.charAt(i)){
        case 0:  // untested cell
            if(_global.turn == _global.playerId) OpponentGrid[i].gotoAndStop(1);  // show fire button
            else OpponentGrid[i].gotoAndStop(4);  // dont show fire button
            break;
        case 1:  // hit
            OpponentGrid[i].gotoAndStop(2);
            break;
        case 2:  // miss
            OpponentGrid[i].gotoAndStop(3);
            break;
    } // end switch(_global.pGrid.charAt(i))
} // end for(i=0; i<100; i++)

the player is able to fire even if it is not their turn, and when the grid is fired on, the grid string (oGrid) is properly updated, but the visible grid does not at all.

The PlayerGrid part appears to work fine, but only the first time it is performed
the correct cells are changed to the correct frame.
however, when the other person fires, the grid string (pGrid) changes correctly, but again the visible grid does not (it does however change the correct cell to the incorrect frame)

I've run out of ideas why this isnt working and hope someone here can offer a suggestion.

ps i'm sorry for the long post, but its a complicated project

Check Current State Of Array Element
I have the following code. I want to eliminate the rollout event so that the menu element which has been scaled remains scaled. On rollover, I want to check the state of the elements and reduce all but the currently selected element back to 100% (ignoring the current element if it was already scaled up).

for(i=0;i<=menu_arr.length;i++){
    
    //set rollover event
    _root[menu_arr[i][0]].onRollOver = function(){
        scaleTo (this, 115, 1);
        createSubMenu(this._name+"_arr");
        section = this._name;
        switch(section){
            case "start":f.fadeAlphaTo(85);break;
            case "models":f.fadeAlphaTo(85);break;
            case "care":f.fadeAlphaTo(85);break;
            case "company":f.fadeAlphaTo(85);break;
            default: f.fadeAlphaTo(0);
        }
    }
    
    //set rollout event
    _root[menu_arr[i][0]].onRollOut = function(){
        scaleTo (this, 100, 3);
    }
    
    //set release event
    _root[menu_arr[i][0]].onRelease = function(){
        if(section == "home"){
            getURL(menu_arr[0][1]);
        }else if(section == "contact"){
            getURL(menu_arr[6][1]);
        }else if(section == "realtors"){
            getURL(menu_arr[3][1]);
        }
    }
    
}


Thanks,

Toga

Excluding Some Numbers From Random Generation
I must be rusty with Flash after not having used it for a few months, 'cause I can't figure this out... (Using MX, by the way.)

Basically, I just need to have a random number generated that will exclude certain numbers from the possible results. This is being used for a tile game where the piece will be randomly moved to another tile, but it cannot land on the same tile as another piece and it cannot land on the same tile from which it is moving.

So, let's say there are 16 tiles and the piece I'm moving is on tile #1. There is also a piece on tile #7. So, in this instance, I will need to be able generate a random number and not have #1 or #7 be one of the results.

Further, it is possible that there will be more than just the two pieces and they will always be in different locations. This seems like it should be simple.

Any help is much appreciated.

Array Problems With Selecting Current Item In List.
I'm still new to arrays, so excuse me if some of my syntax isn't correct.

I've got an array for an audio jukebox and I have a function that plays the current song in the array. Or so I hope. Problem is when I click on the stopSong function it does stop the current song in the array but when I click on the play button it starts all over again at song #1. So if I'm on say song #6 and I click on stop and then play I'm back at song #1 again. Here's the code I'm using for these functions in MX:

playlist = ["audio01.mp3", "audio02.mp3", "audio03.mp3", "audio04.mp3", "audio05.mp3", "audio06.mp3", "audio07.mp3", "audio08.mp3", "audio09.mp3", "audio10.mp3"];
count = 0;
function completeMe() {
count++;
mp3.loadSound(playlist[count], true);
mp3.start();
}
function playSong() {
mp3.stop();
mp3 = new Sound();
mp3.loadSound(playlist[count], true);
mp3.setVolume(50);
mp3.onSoundComplete = completeMe;
}
function stopSong() {
mp3.stop();
}

Seems right, but it isn't. Is it possible to set the playSong or stopSong functions to remember the last track I had played?

Array, Array HELP - Importing A External File Into N ARRAY - Almost There
I am reading and external file with the following code:

ActionScript Code:
on (release, keyPress "<Enter>") {
lv = new LoadVars();
lv.onLoad = function() {
questions1 = this.filelist0.split(",");
answers1 = this.filelist1.split(",");
for(i=0;i<questions1.length;i++)
//trace(questions1[i]+"   "+answers1[i]);
trace(questions1[i]);

//assumes same number of scores in each list
};
lv.load("questions.txt");
}


When I parse the file it puts it into an columar format as it should...however I need it to look like this:

questions1=new Array ("2+4=?","What is the capital of Illinois?","What color is the sky?","10x(5+2)=?");

answers1=new Array ("8","springfield","blue","70");


How do I do that?

Text file look like this:

&questions1=2+4=?,What is the Capital of Illinois?,What color is the sky?,10x(5+2)=?")&
&answers1=8,springfield,blue,70&

Detecting Which Random AttachMovie Loaded From Random Array
I'm building a Freecell type card game. I've got an array that loads all of the cards (actually, the linkage names for each card loaded from the library with attachMovie). I randomize the array before I "deal the cards" onto the stage.

Here's a little code snipet where "deal" starts off equaling 0 and "cardDeck" is the value from my array (for example, c5 equals 5 of Clubs):


Code:
if (deal<52) {
_root.createEmptyMovieClip("card"+deal, deal);
_root["card" + deal].attachMovie(cardDeck[deal],cardDeck[deal],deal);
deal++
}
There's more, of course. My problem is - How can I detect which card loaded into which movie? For example, I know I have a movie called _root.card6 at the bottom of the first column, how can I know what card is loaded into _root.card6?

Random Array
I'm back again. I just started with arrays a few weeks ago and am trying to get my big stupid head around them . I know how to retrieve them but what I want to do is when the user comes to a site he sees a random name every time . So in the main timeline I set a variable with an array called quotes
quotes["john","david", "Joseph", "ted","tim", "Jack"] I think you get the idea . Then in mc I have a dynamic text field called quote the code I have in there is
onClipEvent (enterFrame) {

Random Array Again
I still cant get this to work . I have a array set up in the main timeline .
quotes=["john","david", "Joseph", "ted","tim", "Jack"]
temp=parseInt( Math.random ()*5);
randomName=quotes[temp];

Random Mc`s From An Array...
Could someone help me out with this problem:
When I load an .swf with 12 thumbnails, I want the thumbs to fade in from alpha 0 to alpha 100, one by one (mc`s have alpha 0 when loaded).
The thumbs must be faded in a different order each time the movie is loaded.
I have made a start on it with this code, placed on the first frame on the main timeline. On the second frame is a loop action.

//
fade = new Array (image1, image2, image3, image4, image5, image6, image7, image8, image9, image10, image11, image12);
fadecount = fade.length;
index = Math.round (Math.random()*(fadecount-1));
to_fade = fade[index];

fadein = to_fade._alpha;
fadein++;
//

Somehow I have to store the faded mc`s in an array and pick another random number until the fade-array is empty.

Am I on the right track here?

Random Array Nearly There
not set the timer totally up yet.this is so that it waits a while before ti picks again.

problem with this script more than one plays at a time..whats wrong?
please help?


onClipEvent (enterFrame) {
if (timer ==1 ){
startArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
endArray = [];
while (startArray.length>0) {
i = Math.floor(Math.random()*startArray.length);
// a random item from startArray
item = startArray[i];
// add this item to endArray
endArray.push(item);
// and them remove it from startArray
startArray.splice(i, 1);
// objArray.splice(i, 1);
_root.world["alien"+i].gotoAndPlay(2);
timer++;
}

} else {
timer++;
}
}

Random Array
i need to make something that will randomly access data from an array.

like on the pokie machines. except i need text.

all i have now is

text = new Array("blah1","blah2","blah3","blah4","blah5")

rand = random([text])

can someone help

Random Value Array
I am creating some kind of minesweeper. I must take 10 values out of an array but when a value is already taken it must take another. Can somebody help ...

Kenny



for (var i = 0; i<aantalbommen; i++) {
var bommenlijst = new Array(11, 12, 13, 14, 15, 16, 17, 20, 21, 22, 23, 24, 25, 26, 29, 30, 31, 32, 33, 34, 35, 38, 39, 40, 41, 42, 43, 44, 47, 48, 49, 50, 51, 52, 53, 56, 57, 58, 59, 60, 61, 62, 65, 66, 67, 68, 69, 70, 71);

posbom_temp = random(bommenlijst.length);

posbom = bommenlijst[posbom_temp];
this["vakje"+posbom].blokjestype.blokjestype = "mijn";
trace('bom '+i+': positie '+posbom);
}

Random Array
Im making a game and I need to be able to choose 10 numbers at random between 0 and 100 and put them into an array then I need to be able to find the biggest of the numbers and set that number as a variable so I can test if the wright answer is chosen. That wasn't expained very well, so...erm ill draw something



array: 10 random number (0-100)

function answer: this would find the biggest number in the array and set that number as a variable called "answer"

I need this very quickly so any help would be greatly appreciated.

Random Array
How can I create a grid of tiny grey squares (EG:100x50 squares), and have them turn into a different color (eg black) randomly one by one?

http://sony.net/

I want to achieve something like those squares and those types of transitions.

Also, anybody know a good font that looks like that?

Thanks


--iMat

Random Array
this script loads a RANDOM SWF into mcholder

-----------

lastNumber = randomNumber;
movies = new Array("3com.swf", "abes.swf", "abta.swf");
tempMovies = movies;
newMovie = Math.floor((Math.random()*tempMovies.length));

_root.mcholder.loadMovie(tempMovies[newMovie]);

--------

Now I want to random the rest of the array but not the elements that were loaded before...

example:
- first time: it will random between 1-3... I got a 2
- second time: it will random 1 or 3.... I got a 3
- third time: I will get a 1
- fourth time: it will random between 1-3 AGAIN

and so on...
someone help me pleaase...

Random Array
Hi

Is there a function that randomizes the order of all elements in an array.

thanks
scarlac

Random Array
Hi all!!!, I want to acces an array using random, how can I use it??

Thanx for the help

Mike

Random Array
var question = new Array;

question [0] = "string 1";
question [1] = "string 2";
question [2] = "string 3";
question [3] = "string 4";

My goal is when next time the array loads, the sequence should be changed randomly like,

question [3] = "string 1";
question [1] = "string 2";
question [0] = "string 3";
question [2] = "string 4";


( or )

question [0] = "string 3";
question [1] = "string 1";
question [2] = "string 0";
question [3] = "string 2";

no repetation should be there, all the 4 strings should be assigned for 4 arrays.

XML To Array Then Random
Hi All.

I have created an xml doc that holds 2 values (although I will be adding to the values in time)


HTML Code:
<?xml version="1.0"?>
<urls>
<url>
<name>AAAAA.swf</name>
</url>
<url>
<name>BBBBBB.swf</name>
</url>
</urls>
I want to load these two values into flash then put them into an array, then use "random" to choose a random id from the array.
I want the script to still work if there are more valus in the xml.. here is where im at:


HTML Code:
function loadXML(loaded) {
if (loaded) {
_root.urls = this.firstChild.childNodes[0].childNodes[0].firstChild.nodeValue;
} else {
trace("file not loaded!");
}
}

xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("urlz.xml");

urlvar = ["YSYC.swf", "CS_Havering3.swf"];

// i = urlvar.length;
// k = Math.floor(Math.random()*i);
loadMovieNum(urlvar[k], 2);

stop();
I think my issue here is getting the values into the array and getting the array length 2i"

Random Array
can anybody help me to choose a random array and not choose it again if it play again
so i pick one randomly from it and i don't need it again








Attach Code

myarray1 = new Array(1, 2, 3);
myarray2 = new Array(4, 5, 6);
myarray3 = new Array(7, 8, 9);
r2 = random(3)+1;
mm = eval("myarray"+r2);

Random FLV's From Array
Hi!
I' am trying to randomly load 10 short video clips. The script below doesn't work properly. It plays the first video clip randomly, but then nothing else happens. Please answer my questions below.

script:

var VideoArray = new Array();
VideoArray = ["Q1.flv", "Q2.flv", ......"Q10.flv"];

var currentVideo =random(9);

my_video.play(VideoArray[currentVideo]);

var listenerObject:Object = new Object();
listenerObject.complete = function(eventObject:Object):Void {
VideoArray = random (9)
};
my_video.addEventListener("complete", listenerObject);

QUESTIONS:

1. How to randomly load FLV's?
2. How to make the loaded videos not play automatically?

Thanks for your help.


German
Please check my script and suggest ways to make it work.

Array + Random
Code:
var Count:Array = new Array();

trace (Count)
// _level0.thumbnails.thumb0,_level0.thumbnails.thumb1,_level0.thumbnails.thumb2,_level0.thumbnails.thumb3,_level0.thumbnails.thumb4,_level0.thumbnails.thumb5,_level0.thumbnails.thumb6,_level0.thumbnails.thumb7,_level0.thumbnails.thumb8,_level0.thumbnails.thumb9,_level0.thumbnails.thumb10,_level0.thumbnails.thumb11


bttn.onPress = function() {
var myRandom:Number = random(Count.length);
var goAnimate = animationClips[myRandom];
var fadeTween = new Tween(goAnimate, "_alpha", Regular.easeOut, goAnimate._alpha, 0, 20);
};

Since
Count.length = 12
its like
myRandom:Number = random (12);
============================================

How to make sure, i am cycling between random (12)
Without getting the same results.
But just a cycling between 1 and 12, properly.


Greetz

RANDOM ARRAY
Have put this together but the return value is not what I exspected.
Basically I want one of the four array objects to be randomised.

the_Dates = ["1993", "1992", "2000", "1992"];


onEnterFrame = function(){
var Randoniser = (Math.random(the_Dates.length));
trace(Randoniser);
}

return in the trace
1993
2000
1992
2000
1993
2000
(or something like that)

I know its my syntax and probably the methods i have used that are in appropriate.

Random Xml Array
Hi all,

can someone tell me how can I take one slogan (with all his nodes, bigLines & smallLines) randomly from this xml doc? I use xpath for quering xml: sloganId= XPathAPI.selectSingleNode(this.firstChild, "/catalog/slogan").attributes.ID;

<?xml version="1.0"?>
<catalog>
<slogan ID="0">
<bigLine>Sustainability for all-</bigLine>
<bigLine>tree-hugging optional.</bigLine>
<bigLine>See how we do it.</bigLine>
<smallLine>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</smallLine>
<smallLine>Research Center</smallLine>
</slogan>
<slogan ID="1">
<bigLine>Big, very big buildings</bigLine>
<bigLine>with your signature.</bigLine>
<bigLine>We are different.</bigLine>
<smallLine>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</smallLine>
<smallLine>Some Foundation</smallLine>
</slogan>
<slogan ID="2">
<bigLine>Client relationships</bigLine>
<bigLine>older than our interns.</bigLine>
<bigLine>Visit us, take your time.</bigLine>
<smallLine>Here is some witty copy about the communications.</smallLine>
<smallLine>Discovery Communications</smallLine>
</slogan>
</catalog>

Array With Random
Hi i have some questions in swfs, and i need to let them be shown randomly...But how,

I have them in a array i can get a random swf out using Math.random, but how do i cross that one off so it doesnt come up again???

hope someone can help..

thanks

Stephen

Random Array
could someone tweak this code to choose randomly from these variables in this array?

_root.mwith.heading = ["item1", "item2", "item3", "item4" ];
_root.mwith.floatingheader.slider.slidertext.text = _root.mwith.heading[i];
if (i<12) {
++i;

} else {
i = 0;
}
stop();


Thanks in advance.

Random Array
I have an array of different swf files that I would like to load as an intro page when you visit my site. There are several, I can already choose one specific piece from the array. I would like to select them randomly, so that everytime you visit you can see a new piece.

Random Array..
Hi,

I have a php file containing information that looks like this....


PHP Code:



menu_count=2&menu_title_1=Alli With An I Website&menu_client_1=Alli With An I&menu_tech_1=Flash, PHP&menu_img_1=images/thumb1.jpg&menu_url_1=http://www.alliwithani.com/&menu_state_1=1&menu_title_2=Alli With An I E-Card&menu_client_2=Alli With An I&menu_tech_2=Flash, XML, PHP&menu_img_2=images/thumb2.jpg&menu_url_2=http://alliwithani.com/flash_player/&menu_state_2=1&menu_loaded=1 




Of course I'll add more later and it'll be running from my database allowing me to update from a personal control panel I built.

I have it loading into flash and duplicating a movieclip to display all the projects into a list so people can select them. Here is the code I have for the looping of the MC...


Code:
// This loop duplicates a template movie clip and prepares it based on the information set in "menudata.txt".
item_spacing = 20;
x = 1;
while (Number(x)<=Number(/:menu_count)) {
duplicateMovieClip("menu_template", "item_" add x, x);
tellTarget ("item_" add x) {
menu_title = eval("/:menu_title_" add ../:x);
menu_client = eval("/:menu_client_" add ../:x);
menu_tech = eval("/:menu_tech_" add ../:x);
menu_img = eval("/:menu_img_" add ../:x);
menu_url = eval("/:menu_url_" add ../:x);
gotoAndStop(eval("/:menu_state_" add ../:x));
setProperty("", _y, Number(getProperty("", _y))+Number((..:item_spacing*(../:x-1))));
}
x = Number(x)+1;
}
stop();
It works fine. It loads them into a list as needed. Then if you click on one of the button/mc's it loads the information into a seperate movieclip like I need. But where I run into trouble is that I can't seem to have it automatically load the first set of arrays into the seperate movieclip. That way when people enter that page it's already loaded a project's info in there for them to view, rather than staying blank til they click on one of the buttons. I don't know if some of you can possibly help me add something to the above code to have it select one of the items and send it to the mc right away.

Thanks for your time!

Evan

Array Random
hi guys!
i want words random by example
in the output "two" then test movie "six" then test movie "one"
what is the mistake??
excuse me english

words = ["one ","two ","three ","four ","five ","six "]
for(var i=0;i<words.length;i++) {
words[i]+=random(10)
trace(words[i])
}

Array With Random Function
Can anyone help me with this problem I have a array in the main timeline.
quotes=["john","david", "Joseph", "ted","tim", "Jack"]
temp=parseInt( Math.random ()*5);
randomName=quotes[temp];

Then I have a MC with a dynamic text field inside it and on the mc clip I have
onClipEvent ( enterFrame ) {
this.quote=_root.randomName[temp];
}

I want the names in the array to come up random every time the user launches the MC with the Dynamic text field in it .
The code seems correct but it doesn't work . What am I doing Wrong.

Random Sort Of An Array
here's the problem:

i have a bit of actionScript that generates an array of filenames. basically it looks like this :
loadOrder= ["slideshow/soul1.swf", "slideshow/soul2.swf","slideshow/fashion1.swf","slideshow/fashion2.swf", etc];

there are 12 .swf files in six categories, for a total of 72 files.

now, i want to randomly determine the load order of these files, each time the user accesses the parent .swf. currently, i have the file randomly choosing one of the 72 files, but is there a way to either:

1. randomly sort the array each time so that i can just access in order from index 0 to 71?

or

2. randomly select a number from 0 to 71, but not repeat a number until all 72 possible files have been chosen?

i've tried a few different solutions, but they all seemed to be more complex than should be necessary. am i over thinking this problem, or is it a tricky one?

thanks in advance.

d.

Random Hex Colors From Array
-thanks for dropping in-

This is an attempt to randomly draw 14 colors from a 21 color array. I think everything is correct, but when the 'frame' runs the script, all the objects turn black (0x000000).

Perhaps this is because of a hex color problem with Flash?
I don't know... been messing with it for hours and nothing works.

I think the problem lies in the setRGB() method.
The setRGB() method works when I place a static hex color in it (ex. setRGB(0xFF0000))
There is content in the colorsSelect[Array] when I test by writing it to a dynamic text field.
But when I plug everything together, it causes all the objects to turn black.

Any assistance or ideas would be much appreciated.
Thank you.

=========================================
**(actions in Frame 1 of main timeline)**

// new array with 21 predetermined colors
colorsArray = new Array("0xFF0000", "0x0000FF", "0x990000", "0x996600", "0x99CC00", "0xCC6600", "0xCCCC00", "0xCCFF00", "0x990066", "0x99FF66", "0x9900FF", "0x99FFFF", "0xCC00FF", "0xCCFFFF", "0xFF00FF", "0x00FFFF", "0x000099", "0x006699", "0x00FF99", "0x00FF00", "0xFFFF00");
// filled with 14 random from colorsArray
colorsSelect = new Array(14);
// keep track of random numbers generated
colorsChosen = new Array(14);

// fill colorsSelect array with 14 random colors from colorsArray
for (var randColor=0; randColor<14; randColor++) {
var randNum = Math.floor(Math.random()*21);
for (var compColor=0; compColor<14; compColor++) {
if (randNum== colorsChosen[compColor]) {
var randNum = Math.floor(Math.random()*21);
continue;
}
}
colorsChosen[randColor] = randNum;
cchosen = colorsArray[randNum];
colorsSelect[randColor] = cchosen;

===========================================

**(in Frame actions to generate object colors)**

if ((i <= 7) and (p == 0)){
var pleasepiece = _root.menu["ppiece"+i];
var piececolor = new Color(pleasepiece);
var pieceC = String(_root.colorsSelect[i]);
piececolor.setRGB(pieceC);
i++;
}

------------------

I know there must be ways to streamline and clarify this code. Perhaps my actions should be on the onClipEvent()?
But I had this working with random hex colors and static values. what is the block here?

Thanks again.

Random Extern Swf From Array
hi!
how can i load extern swf´s from an array randomly on my scene?
the target should be a empty mc!
sorry for my english i´m french :-)

kondition = new Array();
kondition[1] = "10%.swf";
kondition[2] = "10%_2.swf";

Random Array Without Repeatment?
How do I make the elements of an array display randomly without repeatment? What I've got so far is the following:

menu = ["a", "b", "c", "d"];
for (i = 0; i < menu.Length; i++){
trace (menu[Math.floor(Math.Random() * 4)]);
}

Thanks in advance

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