Actionscript 3 :: Pick Random Element Of An Array?
Oct 27, 2011I have an array of movieclips and i want to put them on stage. so they have to be unique and randomly chosen.
View 1 RepliesI have an array of movieclips and i want to put them on stage. so they have to be unique and randomly chosen.
View 1 RepliesFor example, when users are connecting to this application they are given a userid var, then it's inserted into the array. So, i'm using chosenUser = usersOnlineArray[Math.round((Math.random()*usersOnlineArray.length))]; to pick another random user. But i need to make sure it doesn't pick the userID they personally were assigned so they don't end up getting themselves. how would i use that code but tell it to "remember, make sure you dont pick userid" maybe I could do something like
[Code]...
pick 1 element in array randomly ONCE
View 1 RepliesThere is an array 'squares' with instance names of MCs that i have on stage. I made a loop to randomize this array, so that every time the randomSquares() function is called, it would show different visible squares. But the problem is that if i call this function twice, same squares are visible as before. Everytime before calling this randomSquares() function, I also call a resetSquares() function.
var squares:Array = [s1, s2, s3,s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18, s19, s20, s21, s22];
var myArray:Array = new Array();
function randomSquares():void {
[Code].....
i am using actionscript 3, and the problem that I have is that i am creating an array of 16 buttons and need to use the function math.random to get it to pick 5 random unique numbers out of the array. as at the moment it is sometimes picking 5 unique numbers and sometimes it has duplicate buttons appearing?
View 3 RepliesI want a movieclip consisting of a dynamic text box that, from the time it's loaded onto the stage, loads a randomly selected text string from an array, and continues to loop until the clip is removed from the stage. I also want the text strings to appear in the text box for random intervals between 500 and 3000 milliseconds.
While I've found tutorials here and elsewhere on loading one element from an array, usually triggered by a button, I don't know how to combine/alter it with the other elements.So I want this movieclip on the stage randomly flashing phrases from an array, some for a barely perceptible time, and others for a readable time.
I'm trying to create a list with an array..My purpose is to put array elements randomly in to the list..But the catch is, I want one array item to assign with 2 list objects..I mean.My arrray is : ["1","2"]And my list is this : "A", "B", "C", "D""A1", "B2", "C2", "D1"
View 1 RepliesHow to import json file in action script and then get random element from json array/object?
View 2 Repliesbut I've spent the last few days trying to find an answer to this seemingly simple question, and no luck. Well, partial luck, but not quite what I wanted.My problem is this - I want to play a random sound when an event happens. In AS2, I used to do this:Actionscript Code:s1 = new Sound();_root.s1.attachSound("sound"+(random(10)+1));s1.start();...where there would in this example be 10 sounds in the library, with names from sound1 to sound10.Now, I want to be able to do the same in AS3. As a temp solution, I've been forced to do a lot of if statements, but that's ugly, timeconsuming and inefficient.I also tried this (AS3):
Actionscript Code:
var soundArray:Array = new Array(new sound1(),new sound2(),new sound3(),new sound4(),new sound5()) var randomInteger:int var selectedSound:Sound function
[code].....
How can I pick random frame from movie clip, so that mc doesn't loop. Movie clip is a symbol. I made symbol defined it as mc, mc contains 4 frames, each frame contains some object.
View 11 RepliesI have a script that when the use types in their name, it is to pick a random name from the list. Problem is, it isn't picking random exactly I get a lot of repeats and sometimes it just comes up undefined.
Here is the script
if (combobox.getSelectedIndex() == 0)
{
txt2.text = "Female Name";
female.play();
[Code].....
I've spent the last few days trying to find an answer to this seemingly simple question, and no luck. Well, partial luck, but not quite what I wanted.
My problem is this - I want to play a random sound when an event happens. In AS2, I used to do this[code]...
i got an XML File with a set of variables which should be chosen randomly. Of course, if one data set has been selected, it should not come up again. to solve this, i created an array called blacklist, which keeps track of all the xml indexes which have allready been selected. so, what i'm doing in f_newtarget is randomize a number between 0-42 and check if it on the blacklist. if it is, i trace "double" and want to restart, and if it is not, write the randomized index to the blacklist and move my target to the coordinate given in the XML.
whats not working is when i get a double event. it traces the "double" but does not start to randomize again. i think i know why, cuz the action is only triggered by pushing the button. but in the case taht the randomized number is allready in the array, i want it to automatically re-randomize r until it finds a value which has not part of the array. what do i have to write in order for the code to jump back to where it randomizes the variable r?
or should i write like a whitelist array from which i randomely deduct the indexes? i have a button which holds the code for selecting a new question. it looks like this:
[Code]....
Needed to place objects on the stage in random order, but only place each object twice. [code]...
View 0 RepliesI have a list:randomPage(["0", "6", "12", "14", "22", "28"]);
and I was wondering does anyone know the code to pick a random value out of the list. At first I just used a random(28) but I need it to go to a specific page and I dont know what to do!
What I'm trying to do now is have 6 characters on stage (these characters are stored in an array) and 2 characters from this 6 will hold a number each and the other 4 will hold an alphabet each. What I want to do is to run this file many times and each time the each alphabets and numbers will be randomly displayed within these 6 characters there will always be 2 numbers and 4 alphabets but I shouldn't know which character will be holding an alphabet and which will be holding a number. I have only two functions now one function is to generate two random numbers to indicate which index of characters to pick to hold a number and then another for loop that run 6 times to addChild on stage.
View 4 RepliesMy problem is that I'm trying to pick numbers out of an array to a cardgame.
Code:
stop();
//var kort = new Array (0,1,2,3,4,5,6,7,8,9,10);
button_1.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
[code]....
Ok what i want to do is to randomly pick 3 values from an array called Objs and add them to a new array called ListObjs. The three values should be unique. This is the code I have so far, but when i try to execute it Flash stops responding.
[Code]....
I have a javascript array and a function on my html page, and I need actionscript to be able to pick the right one from the array and run the function based on what button I pushed. My javascript is:
[Code]...
I'm a little lost on the AS part of it, what would be the best way to have the each different button run it's respective part in the JS array/function?
I have an array with 20 elements and a shuffle function applied. Now i need to screen only 4 elements from that, which then should be deleted from the array in order to avoid repetition (next play will pick other 4 images and so on) Anyone knows if there a class i can use?
ActionScript Code:
function processXML(e:Event):void {
var my_xml:XML=new XML(e.target.data);
my_speed=my_xml.@SPEED;
[code]....
Is it possible to, if you have an array of class names like ActionScript Code: var city01names:Array = ["pic_01", "pic_02", "pic_03" ...] make a new array which would read these names, instantiate them, and push them into a new array containing the instances of all these pictures, which I could then use for a slideshow?
[Code]...
I have an array called dropTarg1 which stores dropped-in items.I want to loop through this array and in a textfield, display each array item on a new line of this text fieldI think I need to use something like Array.join("/n") but I can't get it working properly. I hope that the /n would create a new line of the text field called reviewBoxContentText.
for(var i:Number = 0; i<dropTarg.length; i++){
with(reviewBoxContent.reviewBoxContentText){
autoSize = true;
[code].....
I have 4 buttons and an empty array. When a button is clicked,I'm adding a element to an array with array.push. However, I want to check the array 1st to see if that element exists. If so, then don't add it. Here's what I have thus far
[Code]...
Now I'm taking it I'd have a conditional statement to see if the element already exists. Unfortunatly I cannot just disable the button. I searched the AS dictionary but oddly enough it doesn't have an easy way to search an array. And IndexOf seems to only work for a string.
what is the syntax to pick how can i pick 6 random numbers from 49 numbers
View 9 RepliesI have this array:
[Code]...
I want another array which takes the values of the price from the 1st Array. Can we do something like this? private var another_price_array:Array = [all_array.price]; This second array will be used to populate a ComboBox, or can I populate the combo directly from the first array itself?
I am looking to add some life to this graphic in flash: My goal is to have the "Hey Jude" element drop into frame and be suspended by the two strings that are attached to it. i.e. similar in fashion like a swingset
I have looked all over the web but have yet to find any leads/tutorials on the matter.I would also like this element to be physics based so that the motion is random and when the element is moused over it responds to the action.
I've been putting data into an array via XML, and then selecting at random an image string to load in a pic at random. But whilst doing this, I wanted to remove the String from the Array that I have just used, so I don't get repetition of the same image in the output. I initially thought that pop would remove the string I had just used - But of course it Removes the last value in the Array instead, which doesn't really help.
Ok - so how about randomizing the data once inside the Array, after it has been pulled in from XML!? That way I can load in the 'last' image, and then pop it out! Keeping a randomized selection of images each time 'it' is loaded
i need to split a large text file into an array at line breaks so one array element = one line.i have tried the using "" in both match() and in RegExp but it doesnt work.i had the g and m flags on. tried the $ sign too.
View 8 RepliesI know how to get one element from the array. But I don't know let's say how to take 3 elements ( position 0,1,2). I don't know how to trace all the three together. I am getting errors all the time.
var myArray:Array = [1,2,3,4,5];
trace(myArray[0]);
trace(myArray[0], ?,?);
I have an array like this
public var dataAL:Array=[
{Kiv:"cash", jan:26,janTarget:28,feb:27,febTarget:26,mar:30,marTarget:32,apr:31,aprTarget:32,may:28,mayTarget:29,jun:46,junTarget:32,jul:37,julTarget:39,aug:40,augTarget:42,sep:41,sepTarget:42,oct:48,octTarget:49,nov:40,novTarget:41,dec:38,decTarget:40},
[code]....
Now if i want to access febTarget for cash how will i do it?