Comparing Arrays And Loops
Nov 29, 2010
The scenario is to create a lotto game that matches 6 user inputted numbers with 7 randomly generated numbers. The 7th number is a special case (eg bonus ball) WOULD LIKE TO SHOW A KIND HEARTED FALSH GENIUS ALL OF THE SCRIPT IF POSS! (its not tooo long) This code works, but it just outputs the default message: There seems to be a problem with my arrays not comparing? Part of the code is: (prioir to this the user inputs numbers, they are copied to text areas beginning with O, on a button press) On a second button press randomly generated number appear to a timer. //compareResult checks how many numbers match between the two sets of numbers to determine winnings.
[Code]....
View 4 Replies
Similar Posts:
Apr 28, 2010
I've searched everywhere and can't seem to find a clear explanation or basic example. How do you compare the elements of 2 arrays to see if there is a match?
View 8 Replies
Apr 2, 2011
I'd like to know how to compare one array to another array with objects.
For example:
Array1 = [one, blue, car];
// there will always be only one entry in this array - no Array1[1], no Array1[2], etc.
Array2 = [product.number, product.color, product.type, product.cost, product.qty];
The actual content in Array2 would be something like this:
Array2[0] = [three, green, boat, 100, 5];
Array2[1] = [two, blue, truck, 200, 3];
Array2[2] = [one, red, car, 50, 20];
...and so on, up to about 60.
I'm trying to figure out to go through all of Array2 to determine if there's a match to Array1. Since none of the entries in Array2 are the same, there will always be one match.In this instance, I want to match array1 with product.number, product.color, and product.type. My example has them as the first 3 criteria, though that may not always be the case.
Something along the lines of this:
Code:
function findMatch () {
for(i = 0; i < Array2.length; i++) {
if(all 3 Array1 items equals items in Array2[i]) {
[code]...
Background: I've a combobox search that allows a user to select from drop-downs. After a user selects items from all 3 drop-downs, they click a submit button, and there's a check to see if the criteria in the drop-downs matches anything in the Array2 (which it should, if you can select it, then it's in the array).
After that, the matched information is used to populate a movieclip. There's actually about 20 pieces of information associated with each product. However, I only need to match 3 of them.I've searched and found comparisons for arrays. But I don't see how they'd apply to my issue as I'm using objects and there are more items in array2 than in array1. Of course, they may apply, and I'm just not understanding how. I could create a 3rd array and move only the items needed for a match from the array2 to it. Then I could do a straight comparison between array1 and array3.
View 2 Replies
Nov 3, 2009
I want to compare my two arrays.When both has the same object. they will trace out the name i give.This is the code;
var cap_array:Array = new Array(Sugar,Sugar,Milk,Cocoa);
function ingredients(evt:TimerEvent):void { var ing_mc:MovieClip = null; timer++;[code]......
There is no error in the code; but it can't trace out "cappuccino". Is it I should take the ingredients in order like in the array of the cap_array?
View 6 Replies
Dec 27, 2009
if i have 2 arrays let us say:
array1 = ["a", "d","f","j","g","s","o"];
array2 = ["a","b","n","f","k"];
Let us say i need to check the availability of each item in array2 into array1 and i want to delete it from array1. so if "a" is in array1 and array2, i wanna know that and i wanna delete it from array1.
View 2 Replies
Oct 25, 2011
I have a movie clip called "colors" that contains five clips (squares of different colors). I want to see only one of those colored clips at a time and I want them to be chosen at random (which i've accomplished). I would also like to make sure the same clips isn't selected again until all the other clips have been selected. On frame 1, I set up each main clip as a class:
function clipsClass(){}
clipsClass.prototype = new MovieClip;
clipsClass.prototype.onLoad = function(){
pickClips(this);
}
Object.registerClass("colors", clipsClass);
[Code]....
View 2 Replies
Jan 15, 2012
Im trying to comapre the order and value of two arrays...
[Code]...
The values must be identical by the order and values exp: checkNums[0] == checkBallPress[0]; ps: the array numbers are inputed by user, I typed this values just for the examples sake I tried to do a nested for loop but it doesnt work.
View 3 Replies
Dec 15, 2009
i cant seem to do this:
Code:
firstArray = new Array(item1, item2, item3, item4);
secondArray = new Array (item1, item1, item4, item2);
I basically need to compare the contents of these 2 arrays.
For example when im finished, id like the output to be:
[Code]...
View 3 Replies
Apr 17, 2011
I have two arrays of objects. Each object has a unique name property besides few others. One of the array is a local copy and the other one is sent from server after regular intervals. The local copy of arrays is then used to add a movieclips into a container.Now, I want that when I receive an array from the server, I compare it with the one which is already with me locally such that the items which were not in the received array but were there in the local array, get removed from the container and the newly added ones only get added. The items which were present in both local and remote array remain as it is.
View 2 Replies
Feb 17, 2012
i want to create a function that compares 2 arrays and returns indexes of items found. if for examples my arrays are:
var distances:Array = new Array (0,275,217,385,275,0,251);
var selectedDist:Array = new Array (217,275,251);
i would like it to return 2,4,6
View 2 Replies
Nov 30, 2009
I have this code that's meant to compare two arrays for matching numbers. Depending on how many matches there are, a certain message will be displayed in a dynamic text field. But for some reason it's not working, can anyone figure out why?
ActionScript Code:
var _num:Number = 0;
function compare_Arrays() {
for(var i = 0; i < numbersChosen.length; i++) {
for (var k = 0; k < randomArray.length; k++) {
if (numbersChosen[i] == randomArray[k]) {
[Code] .....
View 6 Replies
Mar 11, 2009
I'm trying to do a simple word counter that counts only unique words. So every new word in the inputWordArray gets added to a wordBankArray, but words that have been used previously would be ignored. I've got something that feels really close to be done but I think I need some kind of switch or break somewhere to keep it from adding on to the end of the array.
Here's my code and the output so far.
PHP Code:
var inputWordArray:Array=["word1","word2","word3", "word1"];
var wordBankArray:Array=["word1"];
var matches:Boolean = false
for (var i:Number = 0; i < inputWordArray.length; i++) {
trace("In inputWordArray loop with "+inputWordArray[i]);
for (var j:Number = 0; j < wordBankArray.length; j++) {
[Code] .....
//What I'm expecting: "Final wordBankArray: word1,word2,word3"
View 8 Replies
Nov 27, 2010
I have the following set up: 6 text input areas when button 1 is pressed these numbers are copied to 6 text areas these 6 (user input) with text areas appear and when button 2 is pressed a further 7 (result) text areas that appear to a timer and contain randomly generated numbers to string I need to compare these two groups of text areas in a way that treats the 7th text area as a special excluded case:
[Code]...
View 20 Replies
Jul 12, 2011
I'm having a hard time wrapping my head around this problem. I have 2 unsorted arrays that need to be compared, array2 must contain all elements of array1 and array2 can any number of extra elements without affecting the result. I don't see any benefits from sorting the arrays and comparing the string values as array2 can have extra information causing noise.
[Code]...
View 5 Replies
Jan 29, 2009
I have some script which grabs stuff from an xml file. The stuff grabbed from the xml is in a loop to create an automatic menu. This is all fine and dandy. Say there are 9 items in the xml file, I get 9 menu items with their unique id's.What I want to do is define an array for comparison against the info taken from the xml file. Say in the xml file I have nodes set up for Apple, Pear, Banana and Orange. With my current script I would get a menu with these items on it. What I need to do is be able to specify the items I want to appear on the menu. For this example I would want Apple and Banana only.
I have experimented with if statements, and it takes too much code to accomplish what I want I am sure there is a more compact way. My idea is to set an array with the items I want in it,then when the information is taken from the xml file,I need the script to do the function of creating menu items only with the items I have specified in the array. Below I have added the code, which has been modified from Kirupa's own squirrel finder tutorial.I need the code to be as reusable as possible, ie only the array would need to change.In my code the variable featureType would contain the information I need to compare against.
Code:
//set limits on the features that need to display
// define array
var featureLimits:Array = ["Apple", "Banana"];[code].....
View 1 Replies
Sep 14, 2005
I would've thought of a better title but I honestly have no idea what's going on. I have this code on the main timeline:
Code:
dots = new Array();
for (i = 0; i < 10; i++) {
[Code]...
View 1 Replies
Aug 1, 2009
I am wanting to create an array. 10 values in it (couting from 0 index to 9). Each 'place holder' will have a corresponding value to it;s index i.e.
myArray[0]=0
myArray[1]=1 etc...
I can do that in a for loop. But then I want to attach each value to a single variable name. I then want to change that each variable to a string. I then want access to all the variables outside of the for loop.
var i:Number;
var aArray:Array = new Array();
for (i=0; i<10; i++) {
[code]....
The output error is 1084: expecting identifier before aArray.
View 1 Replies
May 19, 2011
In PHP you can do something like this:
Array1 = 0,0,3,6,6,6,7,8,8,9
Then loop through Array1 and set the keys of Array2
Array2[0] = true;
Array2[3] = true;
Array2[6] = true;
Array2[7] = true;
Array2[8] = true;
Array2[9] = true;
Array2.count = 6;
But doing a similar thing in AS3 would result in a count of 10 (true,,,, true,,,, true, true, true, true) as all of the keys that are not set are counted. Is there a way of doing this without using any more loops? or Functions, simplicity and efficiently are important here.
View 1 Replies
Aug 1, 2010
I am trying to create a script, where the user inputs a maths equation (something simple like 5 + 2 * 10), I have managed to break down the text into an array and have the numbers in one array and the symbols in another, I wanted the computer to then work it out, however I cant seem to think of how to do this and the methods that I have tried have failed.So there is one dynamic box and the value of that is then broken down by an array split(" "), however this leaves the values in an array and it is percieved as a string not a number and so when i try to work it out
View 1 Replies
Jan 31, 2012
My objective is to create a horizontal menu spaced evenly, using dynamic random widths fed from xml.
I'm playing with arrays in the dynamic loop, but i really have no clue to what i'm doing. Can someone take a look at my loop code, i'm getting all my individual widths but i don't know what to do with them. In the cas e below i get item 1 and 2 in position but the rest are not moving![code]...
View 5 Replies
Apr 24, 2006
I have regarding associative arrays. Basically, I'm trying to use the current index of a for loop, which is looping through xml attributes, as the key for an associative array.
[Code]...
View 9 Replies
Apr 4, 2011
understand how arrays and for loops work together? In the following code 100 rain drops are created with the first for loop and then moved with a second for loop the part that I don't know understand 100% are as follow...
var rainDropArray = new Array();
for(var i:int=0; i<100; i++) {
var rainDrop:RainDrop = new RainDrop();
rainDrop.x = Math.random() * 550;
[code]....
View 6 Replies
Feb 25, 2012
I was trying something out, and came across a little error. I wrote the following code to create an array and, using each value of that array, create an associative array for the values of xVelocity and yVelocity.[code]But I get an error from that as well. I think I understand basically why this doesn't work, but I'm wondering if, given the spirit of what I'm trying to do, you can think of a working alternative.
View 3 Replies
Feb 9, 2009
I want to loop through a array to call my functions, but can't get the syntax right?
var myArray:Array = ['function1()', 'function2()'];
for (var key:String in myArray){
// I want to call the function here
}
View 1 Replies
Feb 9, 2009
I want to loop through a array to call my functions, butcan't get the syntax right, is this possible?[code]....
View 1 Replies
Dec 10, 2009
So basically I have this map. On this map I have points, and when you click on these points it goes to a URL.The code setup is as follows:
Arrays to define the movieclip locations and another for the urls (this one is an associative array). I then create a function loop to make an event listener for each point. When the point is clicked it will run another function that handles the URLs. The URL function is to grab the target point that has been click, use the url array type to find the key, and then throw it in to the URLRequest.
So far I have this code:
var places:Array = new Array();
places = [
map.paulsens, map.paraburdoo, map.plutonic, map.wiluna, map.gwalia, map.wallaby,
map.sunrise, map.moora, map.marvel, map.flyingFox, map.ernest, map.rosebery,
[code]....
So it's obvious to me that the openLink(); function isn't doing what I want it to. I can kind of guess because event.target isn't being turned in to a string or not pulling the array's type?
View 2 Replies
May 13, 2009
it's a scrolling list with a series of movieclips within it which are each different items. When you click one of the items, that movieclip that you have clicked runs a little function which tells it to move 10 pixels to the right smoothly. It also checks to see if any of the other movieclips have been previously selected, and if they have, it runs a function that tells them to move back 10 pixels to the left.
[Code]...
View 6 Replies
Jan 13, 2010
I am dynamically generating buttons and textfields using an array and a for loop. It all works well and creates buttons and textfields ... but once they are created is there a way I can cast them to a movieclip so that I can then control the visibility etc.
Here's the code:
//define variables
var _buttons:Buttons;
var _buttonsX:Number;
var _buttonsY:Number;
var textArray:Array = new Array()
[Code] ......
View 3 Replies
Oct 31, 2009
how can i find out from a for loop that which object from the array has been hit; For eg - i have 2 enemies in an array and i run a for loop
[Code]..
View 2 Replies
Feb 4, 2010
basically what im trying to do is create a jigsaw game, simple eh! i have nothing on the stage at compile time, only four items in the library. these are four different puzzle pieces with export names of "piece01" "piece02" "piece03" and "piece04". my AS goes like this:
ActionScript Code:
var puzzlePieces:Array = ["piece01","piece02","piece03","piece04"];
var len:int = puzzlePieces.length;
var pieceList:Array = [];
[Code]....
how do i or what name do i give the addEventListener to? (if that makes sense)
to be able to drag them.
View 5 Replies