ActionScript 2.0 :: Finding Values In Array - Searching Small Number Of Elements
Feb 3, 2006
I just read the tutorial "Finding Values in an Array". Sure, the code works, but that's only because we are searching arrays the contain a small number of elements. Suppose we have n elements in an array. To search that array for a particular element we may have to do n comparisons. If the array we are searching contains 10 million elements, we have a problem; can you imagine doing "if (this == that)" 10 million times? There's got to be a better way to search the array. Or perhaps we shouldn't use arrays to store the information.
[code]I want to input a number and find a match for the number, returning the values on the row in to specific fields for each number. For example, if I input the number 10 in an input field, I want the number 1.2276, 0.00100, 106.38 and the rest of that row to output these values I have seen so many options, don't know where to start.
i was looking at the tutorial Finding Values in an Array here and was wondering if i could replace
Code: dataValues = [10,9,8,7,6,5,4,3,2];
with a string value thats is read from a text box eg,
Code: dataValues = [myStringValue];
. myStringValue holds
Code: "1,2,3,4,5,6,7"
and only finds it if i type in the full value, how do i get it to find each value seperatley after each comma? Everytime i try that it doesnt work correctly.
So my array has 5 numbers in it and also the ability to add more to it as the user sees fit.I want to be able to display the max and min number in the array. I made a loop but i am not sure how to make it select the highest or lowest number automatically without me selecting it manually by typing it in.This is my code for determining this:
// Determine Min and Max Markfunction maxandminMark(){var markIndex:int;markIndex=(marks.indexOf(marks));if (markIndex != -1){ for (var i = markIndex; i < marks.length; i++) marks[i] = marks[i+1]; trace(maxandminMark);}}}
Say you have a class Parent, which has a property childArray:Array. In this array, we will register several instances of the class Child. Is there an easy way for a child to know which position in the array it currently has? I know I could just pass the index number into the child as I register them, but if a child were to be deleted from the array, all children past the deleted childs index would need to have their indexes updatedl. While this is of course not a huge task, I just have this feeling it should be a better and more dynamic solution.
I have been working with flash remoting in actionscript 3.0 and there is no result set class. I'm fairly new to AS3, but I am very fluent with AS2, and so far the migration has been easy.I would like to create a result set class myself, but I am stuck on one part, pushing the dynamic number of elements onto the array, let me show you what I mean:
{ // start result function var totalCount:Number = rs.serverInfo.totalCount; // # of records returned var queryString:String = rs.serverInfo.intialData; // query string, each value separated
I am using an array to return data to an application and as the array is filled with data using a loader and the order is important it happens that data in slot n is inserted later than data in slot n+1. How do I know that the array is full as I know the number of elements to be loaded? The length property doesn't work for this. I could go through the array each time I put something in and look if every slot is full but that seems ineffective.
lets say i do some simple AS3 math and get a Number of 199. How can i use a Array with values of "preferred" numbers, compare the 199 to the array and round up or down to the closest value in the array?
[Code]...
I want to round the 199 up to 200(closest match) and have the myMatch = the rounded number from the array.
Q. How do I set the width of the array and length and set each of the values in it to the same number.This is for a game im working on. (Tile like you could of guessed.)
Note: I know you use for loops to find the x and y of the values... This doesnt work, but think its how it suppose to work.
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 need to add a small amount of physics to some moving elements.I found flade, but it looks like overkill for what I'm looking for. Also, all the examples are side-views with gravity.
Basicaly, I have a top-down view, and have square shapes that I want to be able to slide along a wall when they hit it at an angle. They don't even need to rotate when they make impact. I tried comming up with my own solution, based on the relative rotations and quarants they collide on, but it is very clunky. I can't help but feel there is a better way to do this. Heck, there might even be some usefull ActionScript function that I don't know about.
I am converting a number to string var myResult : Number = 12.6789345 var myString : String ; myString = String (myResult); I am trying to search . (decimal point) if ( myString.search("."){ } But I am unable to get Result or unable to find " DOT ".
Eversince I've worked with AS3, Flash always seems to have some odd way in rendering pixel-precise vectors. For instance, Friday I tried to draw a roundRect with a line around it. However, when zoomed at 100% it looks crappy and not how it's meant to look:So, when zoomed in in Photoshop you'll see more clearly that it's off:But whenever I zoom in with Flash itself, it looks OK:The quality is set to High, so that can't be it. Is there any flag in AS3 to make Flash render vectors more accurate?
I'm working with tons of array generated from a XML. 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.
Does anybody have an idea how to search the strings in the array? Let's say the user types "ci" to the search field, searching in "taste" (it would be marked). Now it should return the objects which have the string "ci" in the taste, as: apple - acid - red berry - acid - purple..
I have one global array, and I am pushing other arrays (which contain strings) in it. [GOLD, SILVER, BRONCE] [BLUE, RED, GREY, ORANGE, PURPLE] [JUICE, BEER, WATER, MILK, COFFEE] [MERC, BMW, SUBARU, MITSUBISHI, TOYOTA]
Lets say I have these 4 arrays, and I push them into global array in that order. Example 1: if I have string "MILK", I need to search the global array and what I want is to pull out last array (with cars) because "MILK" is contained in third array (going from the beggining). Example 2: if I choose "ORANGE" I want to pull out last 2 arrays (drinks and cars). Example 3: if I choose string from the last array ("MERC") nothing is pulled out. And by pull out I mean just get to it.
I'm working on a grid based game where a user selects a tile and all the tiles with the same colour that are beside it disappear. Up until now I've been using this very rudimentary method to find the neighbouring tiles with the same colour (see below) but now that the game has gotten more complex and larger grids are involved performance is starting to lag so I optimizing the code. have a Tile class like this:
Is there a simple way to ask "Does this array contain this value?" For example I have an array1 [0,2,4,6,8,10] and another array2 [1,3,5,7,9]. I want to say something like:
[Code]...
In this case of course it would find the value "3" in array2 and then do the appropriate action specified there.
Is there any 3rd-party library on AS3.0( like STL in C++) around, can do this:I define my class and use its objects as associative array, for example:
class Company{ var public name; var public logo; var public address; var public telnumber; }
And use a kind of data structure class(say, List) to store a few Company-type objects. And then, I define my own comparing and searching function on that List class(namely, override the default one); within my functions I could specify on which attribute(name, or address, or telephone number) to perform searching, and how it would be performed.