Flash :: Unable To Get Length Of Array
Mar 14, 2011I am unable to get the length of the array.[code]...
View 3 RepliesI am unable to get the length of the array.[code]...
View 3 RepliesLet's say I have array foo and a positive integer y, where foo.length > y.I want to remove elements from foo so that foo.length becomes y (or very close to it).Also, I need to preserve the first and last element of foo. The indices of the removed elements must be spaced apart as equally as possible. Foo can be sliced, or it can be used to create a new array.
Example: if foo = [a,b,c,d,e,f,g,1,2,3,4,5] and y = 6, then trimmedfoo could be [a,c,e,g,2,4,5] or maybe [a,c,e,2,4,5], but not [a,c,e,g,2,4] because the last element of foo is missing.
I am trying to get the length of arrays within an array, here is my example (MX 2004):
[Code]...
I get an output of of 3. the number of variables within the first array, this is not what I had expedted.
Here is my main file:
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="[L=http://www.adobe.com/2006/mxml"]http://www.adobe.com/2006/mxml"[/L] layout="absolute" xmlns:comp="components.*" initialize="xmlData.send()">[code]....
will pass in the dataGridData into the component. But my component (private var dataLength:Number = dataGridData.length) was unable to get the length of dataGridData, and giving "Cannot access a property or method of a null object reference" error message. I debug and realized at the time flex initiate this variable, the data "dataGridData" haven't past in yet. It was past in later.So how do I change my code to let it able to get the length after the dataGridData have past in?
This is my first time posting to a forum as I have been unable to find the solution to this problem. I am receiving an array from a php script in this manner[code]...
View 1 RepliesI have an array with many values pushed into it (happen to be names of objects). I am using a for loop to check all of the objects (by index number) for collisions, etc. Periodically, depending on a condition, I want to remove the currently checked object's name from the array list. I noticed that there is a problem if I immediately splice the checked name from the list. Namely, the list gets shorter, which is what I want, but not until I'm done checking all objects. Is it a good idea to solve the issue by incrementing i-- after the splice? I do this so that the object that used to be next in the list doesn't get skipped.It seems to work very well but I want to know if this is a lame/problematic solution and if there are any better ways of dealing with it
for (i=0;i<myarray.length;i++){
var ob=myarray[i]
//any old condition
[code].....
I'm using the .unshift method therefore the newest values go into [0] and the rest are pushed down.
What is a good method to remove a value from an array once it has passed a certain length? For example i only want my array to hold 5 values.
Also, is there a method for clearing the entire array, ie removing all values? Or will i have to manually change all the values with a loop?
im trying to use array.length to get the total indexs of the array, before running a loop on all of thoes indexs when i attempt to do this(i added a few extra things for the sake of debugging and understanding)
ActionScript Code:
var selectcharacternames:URLVariables = new URLVariables(evt.target.data);
trace(selectcharacternames)[code]....
does array.length not work with url variables is it possible to turn url variables into a array(im assuming it is not a array as a reason why this doesnt work)
I have 2 arrays:
Array 1 = [1,3,5,7,9,10];
Array 2 = [5,7,10];
Now, I wanted to create a new Array the is the same as the length of Array 1. The output should look like this:
New Array = [0,0,5,7,0,10];
I am trying to learn xml in flash myself and am findingit v.hard.All i am trying to do is create a little 'story' with 3 pages.I have content loading into flash but I am unable to get the next 'sibling' into an array e.g. the title. I can only get page1's title in the array but I can never get to page 2.Here is my xml:
<maincontent>
<page1>
<title>Who is he</title>[code].....
This only traces the first title, how can i get to the second and the third so i can then display them in my text box?
this problem is blowing my mind i have a for loop that i want to go through my entire array but it seems to not be counting the last element in the arraay!
Code:
for(var i:int=0; i<gridControl.game.blockG.length; i++){
trace(i +" "+gridControl.game.blockG.length);
}
and the last line of code it spits out is "83 84" meaning that there are 84 items in the array but it only ran through to 83...i dont understand why its doing this.
I need a way to read the length of my array, automatically create that many frames in the main.fla and read each screen from my array and display it accordingly on each frame. How to do this?
E.g.. In A.xml, I calculated 10 screens, so Ii need to create 10 frames for A.xml....and in my B.xml, I have 25 screens, there Iit should create 25 frames.
I've got some coding to create buttons into an array, and on press of these buttons the function should remove something from another array and remove the last one of the line, so far the coding is working for the first removal, however thereafter the other buttons stay there I think it's to do with the line in bold but I cant put my finger on what's wrong with it! The trace's I've set look plausible...
function removeList (event:MouseEvent):void{
myArray.splice(0,1);
list_text.text=myArray.join("");
[Code].....
I like to use array.length in my for loop to keep my code cleaner to read. Is there any huge downside to this? For example will it speed up things greatly if i store the length in a var one time?
View 22 RepliesI am trying to get the length of an array through mxml (not actionscript). I have the following:
<s:Application
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
[Code].....
Why does test2 show the correct array length but test1 is stale?
I want to create an array which at first stores nothing until data is pulled from a db.This works fine for when there is only a single column index like:
arr1 = new Array();
arr1 = [
["a1"],
[code]......
How can I find out the length of the second dimension in a multidimensional array?
this is not working:
Code:
trace(my_array[i].length);
(i being a number incremented by a for-loop (starting at 0 of course))
How would I go about checking the length of a sub array? If I have a code like this:
ActionScript Code:
a = [["a0","a1", "a2", "a3","a4","a5"],
["a0","a1"]];
and I wanted to check the length of the second subarray (the answer would be 2) what would the syntax be?
Edit: the title should obviously be Multidimentional.
As we have in other languages like C, Java that once we define the length of an array we cannot assign any value to the array beyond it's length.[code]This kind of stuff is not possible in C and Java.However AS2.0 calmly accepts the value and increments the length of ii (array) from 3 to 5.Is there any means to restrict the array to accept only particular number of data.
View 10 RepliesI want to know the length of a xml. From a xml file I can make it work. In this case it's a database that generates the xml. So it is a URL, not a Xml. How can I make this work?
Code:
// loading xml //
url_xml.onLoad = function() {
// this is the array I need from the URL //
var array1:Array = url_xml;
[code]....
I have this code working which has an XML file. This is the code for XML menu(no drop down) for website , i am working on, but i wonder when i traced the value of both arr2 & arr1 it returns 0, although i pushed the value.[code]
View 2 RepliesI am trying to get the length of arrays within an array, here is my example (MX 2004):
this.menu.o= ["option1","","container"],["option2","","container"];
context="o";
trace(this.menu[context].length);
I get an output of of 3. the number of variables within the first array, this is not what I had expected.
I have an array which contains strings. I need to sort the array by the length of the string - longest string first.
e.g. if
myArray[0] = "xxx";
myArray[1] = "x";
myArray[2] = "xxxxxxx";
[Code].....
but it didn't work. I guess length is not a property of each array element.
By the way, the array is already large (270,000 elements) - so I need the sort to work very fast, and I don't want to be adding anything else into the array.
I have a question i need to get the length of an array but outside the onLoad()
here is my code:
var O:XML = new XML();O.ignoreWhite = true;O.onLoad = function(success) {
var photos:Array = this.firstChild.childNodes; _root.PanelH = photos.length*200; trace(PanelH);};trace(PanelH);O.load("VideosBank.xml");
How do you find the length of an Associative Array? The standard "arrayName.length" returns 0.
View 2 RepliesHow 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 I am working on. I know you use for loops to find the x and y of the values... This doesn't work, but think its how it suppose to work.
Code:
_global.ymap = 4;
_global.xmap = 4;
for (y=0; y<_global.ymap; y++) {
for (x=0; x<_global.xmap; x++) {
_global.map[y][x] = 1;
}} trace(_global.map[4][4]);
I am attaching mc's from the library using xml to populate the textfields. What I am wanting to do is show the first six mc's, then after say 10 seconds show the next six. With a text field displaying "1 of 3", after 10 seconds, "2 of 3" ....etc. A bit similar to image galleries really (sorry if I haven't explained this very well).Anyhoo, heres what I have so far, it loads the mc's one after each other:
Code:
import mx.transitions.Tween;
import mx.transitions.easing.*;
[code].....
Does anyone know how to sort an array based on the length of the instance name?
I have an array full of instance names and they are different lengths. I need them to sort based on the number of chars.
I wondered if anyone that uses multidimensional arrays can tell me how to get an array length value for each 'layer' of data.[code]
View 6 Repliesit would seem (and I guess I read Senocular's thing on this ages ago, but never really believed it)...
Code:
var a:Array = [];
a[0] = "a";
a[1] = "b";[code].....
But make it sparse and it all goes to hell... i.e. if a[0] isn't defined, cases where you're using it as a piece of useful information, there's no guarantee they'll spit out in the same order.On the other hand, if you make it an object, you can't get its length.Does anyone know an elegant way to poll an Array for the number of occupied addresses, and allow it to for/each or for/as in the right order? In PHP it's as easy as count() and foreach(... as $k=>$v). While the latter doesn't do much good for associative arrays, it always works in order on numerical arrays, whether sparse or not...