ActionScript 2.0 :: Pick 1 Element In Array Randomly Once?
Feb 13, 2012pick 1 element in array randomly ONCE
View 1 Repliespick 1 element in array randomly ONCE
View 1 RepliesOk 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 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]...
i'm using Mx Flash and i am making a game. it is called "falldown". the 'ledges' that you run into as you are falling down need to go up. i have the mc that moves up and all, but there needs to be three of them that move up to keep you from hitting the bottom. i need it to randomly pick from the three mcs as the first one reaches a certain point. in case you don't understand ask questions and i am going to post the .fla when i get on my own comp.
View 2 Repliesi'm using Mx Flash and i am making a game. it is called "falldown". the 'ledges' that you run into as you are falling down need to go up. i have the mc that moves up and all, but there needs to be three of them that move up to keep you from hitting the bottom. i need it to randomly pick from the three mcs as the first one reaches a certain point.
View 2 Replies[Code]...
I it to randomly pick one of the childNodes and display it in the container. I tried to place in a Math.random(); but I wasn't sure where to put it.
My 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]....
There 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 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.
I 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 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?
How can add element to array in ActionScript3
If i have an array: var myArray:Array;
How can add element to this array "myArray", something like this:
myArray[] = value;
My second question is: How can compare if variable value exist in array element value?
Something like in_array function in php
I'm trying to make a memory like game. It might be called Simon or Simple Simon or something. Basically something is shown for a second and then gone, then the user clicks that something. Then two or three things are shown in order and then gone and the user clicks the order.
I'm stuck at the very beginning, just showing something from an array for half a second or so then stopping and then starting over and adding one more element.
This is for a small RTS prototype I'm working on for some fun, but I've hit a snag.
For examples sake, I've got two arrays, activeAgents and houseArray. A number of movieclips (player controled units/agents) are stored in activeAgents and houseArray is used to store any agent that is "inside" the house.
If an agent in activeAgents hitTests the house that houseArray belongs to and the agent ISN'T already in the houseArray, then I want to add the agent from activeAgents INTO the houseArray.[code]...
Code:
arrayA[i] = arrayB[j];
This results in:
1:[object #7, class 'Array'],
I'm would like to set arrayA[i] to the value of arrayB[j], not set arrayA[i] to the object arrayB[j].
I can't use .toString() as I'm trying to pass on an array inside an array.
the code below loads only the second member of the "koan" array. why it isn't randomly loading swfs? (Could it be a problem with the "var index"?...when it is changed manually in the code from 0 to another number the swf played does change; but still not randomly.)
[Code]...
I have an issue where I would like to remove a sprite randomly in AS3, I have managed to figure out how to create the sprites so that they fill as a grid, just for the life of me I can't figure out how to remove them!Here's the code i've used to create them:
function showpixels() : void
{
for (var i:int = 0; i < 40; i++)
[code]......
I am trying to write a function that is passed an array and will then reorder it randomly and return the array. My problem is that as the position is generated randomly I dont know how long the loop must run for, this function doesn't work but it should give you an idea of what I'm trying to do:
[AS]
function randomise(the_ar:Array):Array {
var ret_ar:Array = new Array();
for (i=0; i<200; i++) {
[code]....
I'm building this simple platformer (one level, block graphics, just to get the basics down). I have this array system set up:
[Code]....
I have an array used to track shots fired from a cannon, and when they hit the ground they are removed.
I would like to know what is the most efficient way of finding and removing a certain element from an array. I heard that using pop() instead of splice() was faster, is it ?
Also, the big question I have is that the only way I see of actually finding the element in the array is using
Code:
for(i=0;i<array.length;i++){
if(array[i] == movieClipToRemove){
//i == movieClip index in the array
}
}
Then I would use either splice() or pop() to remove it from the array before deleting the MC. Is there a better way than scanning through the whole array comparing each element to the triggering MC ?
I've got an array containing various sprites... I'm wanting to reference the sprite I want by its name rather than its index in the array, and was wondering if theres a simple way of doing this? I know I could do a for loop through all the array elements and see which one has a name that is equal to the name im looking for, but is something along the lines of myArray[elementName] possible?
View 5 Replieshow to remove a particular element from array
View 1 Replies