ActionScript 3.0 :: Fast And Efficient Array Search Method?
May 9, 2009
I am populating an array employees (shown at the bottom) with data from a MySQL database table. To locate employees that statisfy a complex criteria, I am using a loop like so:
var emplyees:Array = new Array();
var i:int;var counter:int=0;for (i=0;i<employees.length;i++){
if((employees[i].city=="London")&&(employees[i].age<30)){ counter=+; }}if(counter==0){ trace("No such emplyees")}else{ trace("Found "+counter+" employees.")}"
It works fine, but I think it is cumbersome and potentially slow with large amounts of data. Is there a better way of doing this?
I can make a slideshow by importing 30 or so images and using the timeline. I can make a slideshow by importing 30 or so images and using actionscript so that the timeline is realtively short.
What is the best way? I discovered how to do it by loading a movieclip with the image, but that is risky because depending on the connection, it sometimes loads too late.
What is the most streamlined, small filesize way to make a long slideshow? Can you point me to posts that talk about this or tutorials?
Long story short: I want to search a multidimensional array in AS3 for (in this example) the location of 6 strings - all of which are stored in another unrelared array. Long story long: Once I get the locations (in the multidimensional array) of each string, i then know where it's located, and can access other atributes of that object - so if i found the string "box3" is located in element [5] of my multidimensional array, i can now target: multiArray[5][3] to return the 4th item stored (keeping in mind we're starting from 0, so 3 is the 4th position).
I can get this to work once, but I'm trying to set up a for loop based on the length of my basic string storage array - this array holds (in this example) 6 instance name strings - each time my for loop loops, i need to run a search in my multdimensional array for the next consecutive instance name. Then, once I've located all of them (and store the results in a new temporary array) I can dig around in each location for the info I need.
To save people from reading too much, this is the "abbreviated" version, while the next post will contain the "full version" in it's original glory. Here is the deal. I have a "User" class with 4 properties, all Strings. I want to store those instances inside of a "UserList" class. The UserList class has several properties to sort through and find users. Now, at least the "getUserByPrefix" and "getUserByNickname" require to retrieve values very quickly, so (I'm guessing) that options like this are not a good idea:
I haven't experimented with external SWF's purely as image/sound libraries etc. I generally embed assets and/or load in sound/textures/geometry etc dynamically.
However as I'm starting development on my first game, I would like to use an asset SWF per level, so all images, sounds, models etc are contained in this SWF, nice and clean, just one file loaded per level. No code, just assets.
Not only for the structure, but embedding transparent PNG's is very important, as obviously uncompressed PNG's are pretty hefty, and flash does a great job of it.
So for those with experience of asset SWFs, what do you think is the best method of loading/removing/accessing/managing them?
Code: if(i>4){ trace("end of itemsloaded"); _buckets.reverse();
[Code]....
and then in bucket intro I call the array and they're not reversed yet.. but if i add another function between the two, then it gets reversed in time??
The content of the array respuesta is: Africa, Europa, Norteamerica. The content of the array resultado is: Incorrect, Correct, IncorrectI created a Array to include both of them:
var contPre:Array = [ this.respuesta, this.resultado ]; and then: for ( var row:int = 0; row & lt; contPre.length; row++ )
How should I go about creating a search function that will be able to search and retrieve a particular nod from the array.Sth to do with .toLowerCase() and getIndexOf? The search function should be able to search and retrieve any text that contain the letter/letters... not the whole word. Like for example if user enter "gre", it should retrieve results containing "great" and so on.
I am curious if this is an okay implementation of the Array.filter() method.
[Code]...
I was not able to figure out an implementation of the callback function for the filter() method, where the callback was outside of the getGallery() function. I wonder if there is a way to get the isGallery function outside of the getGallery scope?
I've been trying to move array elements from one array to another using the push method. The problem is that the element pushed should any longer be on the first array where it was taken from. That's where i'm stuck..
You see, I would like to make a login page that retrieves the username and password from a text file. All login information is stored in an array, which looks like this:& Users =::: Name1 | username1 | passwords1 |::: Name2 | username2 | passwords2 |::: Name3 | username3 | passwords3 |I want to find in my arrayif the user is authorized. If it is authorized, I would like to send the name (Name1, for example) into a text box. How do I do?
I am working on an application in Actionscript 3.0 that is working with twitter, I got as far as getting the tweets I want in an array but now comes the hard part: I only want to show the tweets that mention another twitter user. Now I know that mentioning another user in Twitter always with an @ (like @username). So I want to show all tweets with an @ in it.
I have a small array with some elements and a big array with all the elements. I want to search in the big array the small array to see if they exist. Is there a function to do that ?
Alright, so within my final swf I need to have a function that searches, but not searches the internet (such as integrating a google or bing search). It will be searching though data that I have already collected. My data is in the form of CSV (comma separated values). I already load in the csv and all that jazz, no problem (using url loader). I put the data into an array. I can conduct the search in a few ways and I was wondering what everyone in the forum thought would be the best way. The data also gets attached as parameters to objects that I put on the stage, if that matters.It must return all things in the array that match the string typed in the search, and not just the first match it finds.
So i need to search through a multidimensional array.. here is an example of what the user will see when searching the array
First name: Last name: grade:
now what i wana do is make it so the user can search through the multi/array with the first name to find the last name and grade that goes along with it... here is my failed attempt.
ActionScript Code: var dataArray = new Array(new Array(), new Array(), new Array()); var tempArray = new Array(); var eMode = null;
I am working on an application in Actionscript 3.0 that is working with twitter, I got as far as getting the tweets I want in an array but now comes the hard part: I only want to show the tweets that mention another twitter user. Now I know that mentioning another user in Twitter always with an @ (like @username). So I want to show all tweets with an @ in it.[code]And off course that's not going to work, it only displays the tweets that match exact (all 140 chars) with the search var. After some searching I found this:[code]
i have a variable 'val' and 5 arrays 'roomNums1' - 'roomNums5' i want a script to search one of those arrays ... i can get it to search one array but i can't get it to search the array with the name 'roomNums+val'
so if val = 2 i want it to search roomNums2
at the moment I'm just telling it to trace the array that I want (for testing purposes) and the script reads:
trace (roomNums[val]);
but that takes the 3rd value in the array and traces it if val = 2
i'm not sure how to add the value of the variable val onto the end of the array's name so the correct one will be traced
I'm trying to detect multiple elements in an array. My countTicks:Array contains mostly numbers and below you can see I'm using "logical AND" to try and find them.
The problem is, once I have more than 2 "logical ANDs" (&&) the trace gets called. Which it shouldn't because the array wouldn't yet hold those numbers.
PHP Code:
countTicks = function(){ for (var i = 0; i < tickCount.length; i++){ if (tickCount[i] == 1&&2&&4&&5){
How would I go about making a search function that can locate an array of buttons?
The buttons direct to movieclips. The purpose is to have a search field in the flash project to help find specific movieclips (the buttons that direct to them, anyway) based on criteria using arrays. I am using Flash8, but have access to CS4 if necessary.
I have a standard array with some text items and some numbers.
Here is an array item
ge: 65, (no quotes around this number)
Here is the DataProvider line (the section that applies to my example)
DataProvider([{label:"over 60", data: 65}]);
Here is the search line
for (var n; int = 0; n<arrayname.length; n++
arrayname[n]. Age == search_age.selectedItem.data
This works fine because the array number MATCHES the selectedItem data number (65) exactly and I get all records where age is 65
BUT I want to find records whose age is any number "greater than 60"
I have tried many ways to use the > sign and keep getting an error, example:
DataProvider([{label:"over 60", data: >60}]); or DataProvider([{label:"over 60", data: (>60)}]); or DataProvider([{label:"over 60", data: >(60}]);
None of these work.
Maybe these aren't numbers? I've tried putting 'int' in various positions with no results. I'm using a DataGrid which works fine for text items and will find numbers without quotes around them (if those numbers match whats in the array!).
What's the way to write this so I can get records greater than, or less than, etc.?
Premesis:I am using actionscript with two arraycollection containing object with value to be matched...Let's assume I have two list of elements A and B (no duplicate values) and I need to compare them and remove all the elements present in both, so at the end I should have
in A all the elements that are in A but not in B
in B all the elements that are in B but not in A
now I do something like that:
for (var i:int = 0 ; i < a.length ;) { var isFound:Boolean = false;[code].....
I cycle both the array and if I found a match I remove the items from both of the array (and don't increase the loop value so the for cycle progress in a correct way).I was wondering if (and i'm sure there is) there is a better (and less CPU consuming) way to do it...
i do have problem with searching through my multi-dimensional Array to insert newly value to currently existing value..here's the scenario...what I have now....
Code: var someArr:Array = new Array(["apple"],["orange"],["watermelon"]);
so what I wanna do is I able to search the desire valeu 1st and append to existing value eg;
word search = apple
match and I can append new value to this particulars array and my expecting result
new array after append new value
Code: var someArr:Array = new Array(["apple","expensive"],["orange"],["watermelon"]);
I have an array index problem. I have an Array that holds some strings. I am trying to write a function that receives a string variable (user input)and searches for that string in the array. for that i tried to use "ArrayName.indexOf(input_variable)" but this always returns -1 even if the string which the variable holds is in the Array.
This is the script: public static function ValidName(inputName:String = ""):Boolean { trace(validNames.indexOf(inputName)); if (validNames.indexOf(inputName) > -1) { return true; } else { return false; }}
I have an array which I am populating as I navigate through the site. Sometimes due to cicumstances apparently out of my control, I end up with two (never more) duplicate values consecutively placed in my array, here is an example:
I need to run a script at all times that checks to see if this happens, and removes the second duplicate value, as well as it's corresponding key.How can I do this?
I am currently in the process of making an image gallery at university over the period of the semester. Eventually it will be able to search through flikr and pull thumbnails from there but for now we are just getting the fundamentals working. Last weeks task was to have the int amount of thumbnails show up depending on the number u placed in the search field.
So in other words i type in 3 in the search field, and 3 placeholder images show up. The problem is having to remove them from the stage and the array so that when u type in 2 or 1 after having typed 3, that it erases the last search results from the array and the stage. This is my code below which half works. It will place however many images you tell it to, but will not erase them next time u press search.
Problem is that my rewind and fast forward buttons do not work properly in the sense that they start to mess up when you fast forward or rewind past the current scene. It seems to just skip through the whole movie and totally mess up the animation.the code for the controls is on a single layer and reads as the following:
I've just tried senocular's xml tutorials. [URL] The search query seems case sensitive. How to make it accept upper and lower case characters. Actually i'm trying to make a search by myself by using the same code.