Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Array By Index Question



I have this array with three values

ActionScript Code:
var myArray:Array = [91,77,65,];
I need all three values in the array because im using it by index,but what I need is when i press on a button for it to only call the third value of the array 65 and not call the other two.what i'm doing is moving a movie clip to the numbers specified in the array but only need the third value.
hope this makes sense



ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0
Posted on: 06-28-2006, 12:45 PM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

ARRAY Element Value - Not Array Index Value
Hi all -
Have a small problem converting the below variables from PHP into a useful Ascript Array. I keep getting the value of the array index, rather than the value of the variable in question.


So I know I have 3 rows in my database (totalRows var),
and I have a incremental values for the "recordId"'s (which correspond to the record ID in the db).

totalRows = 3

recordId0 = 1
recordId1 = 5
recordId2 = 6

this is the code I am using:

Code:
function extractMenu() {
//returned vars (FYI): totalRows=3&recordId2=6&recordId1=5&recordId0=1&result=okay&
this.menuArray = new Array();
with (menuLoad) { //menuLoad is the LoadVars object holding PHP vars.
for (i=0; i<=totalRows-1; i++) {
menuArray[i] = recordId + i;
trace(menuArray[i]);
//the trace returns:
//0
//1
//2
//I was expecting the values:
//1
//5
//6
}
}


any takers?

Help - Getting Array Index 0 With MultiDim Array
Howdy,
I've attached a file for some help here. I'm creating a menu structure in flash and need to pull certain names out of multiple arrays. I had this working before the arrays became multidim. Now that the arrays have become multidim the chapter heading names are all whacked. The chapter subpages are fine though.. When the file is previewed it's pulling a 0 index for one chapter header, but after that it's pulling the supbage indexes. Basically the headers of the menu need to be the [0] of the arrays.

Any help or suggestions would be helpful

thx

B

Help - Getting Array Index 0 With MultiDim Array
Howdy,
I've attached a file for some help here. I'm creating a menu structure in flash and need to pull certain names out of multiple arrays. I had this working before the arrays became multidim. Now that the arrays have become multidim the chapter heading names are all whacked. The chapter subpages are fine though.. When the file is previewed it's pulling a 0 index for one chapter header, but after that it's pulling the supbage indexes. Basically the headers of the menu need to be the [0] of the arrays.

It's under the note // populate chapter headers with text //

Any help or suggestions would be helpful

thx

B

How To Index An Array
I should know this; I think I once did . . . but for some reason my brain is frazzled and I am turning up nothing, not in books, nor on the internet.

All I want is to return the index of an array element. Really, that's it.

I am storing ID values for news stories in an array and I want to make a "previous" and a "next" button -- so I want to take the index of the current ID, add or subtract one, and then send that value to my loading function.

Please, someone save me from myself.

Ed

Array Index
flash mx

i have an array (arrayA) with length of x, and i have a variable (y) with randomly assigned values between 0 and x

i assigned a random value for x, then in the same frame, i have a dynamic textfield, i want to display the value of arrayA[y], but it doesn't seem to work when i put arrayA[y] in the var field of the dynamic textfield...

please help...

Array Index
hey guys

i am loading the name of the images 4rm the database and storing in an array is it possible to get the index value of the image inside the array

for eg
my array:Array=["image1","image005","image7","image15"]

all this images r displayed in an thumbnail
when i click on the thumbnail is it possible 2 retrive the image index inside the array so i can navigate thru

say previous image and next image

Tnx in advance.

Shom

Specify Array Index
Is there a way I could specify the index of a array using this short code:


ActionScript Code:
var myArray = new Array("teste");


How would I go about giving a custom index name instead of it being myArray[0]? I could do it the long way like posted below, but I was wondering the there was a way to shorten this:


ActionScript Code:
var myArray = new Array();myArray[myCustomIndex] = "testing";



Cheers!

XML Array Index. Help Me Pls...
<?xml version="1.0" encoding="iso-8859-1"?>
<genealogy>
<g1>
<Director title = "Son" />
<Seffire title = "Daughter" />
<Jain title = "Sister" />
<Stropper title ="Mother">
<Kirupa name = "Kirupa"/>
<NovemberRain name = "November Rain"/>
</Stropper>
</g1>

</genealogy>

Above is the XML file. I've a function to reade the nodes of the XML that is "dispTree". xmlStr is the XMl Object.


_root.dispTree(xmlStr.firstChild.childNodes[1], 3);

The call returns "Jain"

What is arrat index we can refer Kirupa.

is it something like _root.dispTree(xmlStr.firstChild.childNodes[1], [3][1]);

I'm little confused how to pass that node index to dispTree function (Kirupa node)

Any help will really appreciable

Specify Array Index
Is there a way I could specify the index of a array using this short code:


ActionScript Code:
var myArray = new Array("teste");


How would I go about giving a custom index name instead of it being myArray[0]? I could do it the long way like posted below, but I was wondering the there was a way to shorten this:


ActionScript Code:
var myArray = new Array();myArray[myCustomIndex] = "testing";



Cheers!

Array Index
I know its possible to extract a data item from an Array using and index number but is it possible to extract an index number by specifying a data item or string?

Follow me?

Is it possible to do something like the following?


ActionScript Code:
myArray = new Array ("Tom", "Bob", "Harry", "Mary");
trace (myArray.indexOf("Bob"));

Deleting The Last Index Of An Array
here is my code:
-----------------------------------------------------------
myArray = new Array("hi","my","name","is","bob");

for(i=0;i<5;i++)
{
listBox.addItem(myArray[i]);
}

myButton.onPress = function ()
{
listBox.removeItemAt(myArray[myArray.length-1]);
}
-----------------------------------------------------------

when i click on the button it erases the first index namely "hi" But I thought I had it set up to erase the last index. Can anyone tell me what is going on here?

An Array / Index Issue
Hi,

Does someone know an array method (or something else) that returns the index of an element of this array.

For instance :

array[0]="joe";
array[1]="nono";
array[2]="dudul";
array[3]="titi";

If I ask to this "method" the index of the element "joe", I expect it to return 0.

If I ask to this "method" the index of the element "dudul", I expect it to return 2.

It sounds easy... did not find the method through the actionscript dictionnary though...

Thanks for your help

Get Dynamicly The Array Index
how do I get the value of an array dynamicly?

myArray = [];
myArray[0] = "peter";
myArray[1] = "simon";
cnt = 1;
trace(eval("myArray["+cnt+"]"));

output window:

undefined

thanks

For Loop And Array Index Zero
when i do a trace of my array i alwasy get an undefine first (index zero).... why is that?

how can i get the pushed item into index zero when the array is empty, by not telling it direct (array[0] = "me"); and then being able to output it to my window?


Code:
on (release) {
array.push ("me");

var size = array.length;

for (var i = 0; i >= array.length - size; --i)
{
resultBox.htmlText += array[i] + " ";
}
}


thanks in advance
Hector

Finding An Index In An MC Array
FP v. 7. AS v. 2.0
_____________________

I have 10 MCs called "button0", "button1", "button2", etc. inside an MC called buttonsHolder.

I can access each "button" mc this way:

_root.buttonsHolder["button" + index]

This is what I have inside each "button" MC:

on (release) {
_root.buttonPanel[this].gotoAndStop("on");
}

I know I can find out button's number by using substring() on "this", but is there another way to find out the index of "this" inside buttonPanel? I couldn't find any methods or properties for that.

Any ideas?

[F8]String Index In Array?
Hey guys, in php you can use strings instead of numbers as the indices for arrays. I think it's like this:

PHP Code:




$array = array("indexString" => "value");





Anyone know of an equivalent in flash?

Array With String As Index
Hi,

Is it possible to do an array under AS3 with strings as index ?

something like :

myArray['item1']="Hello";
myArray['item2']="World";

thanks a lot,

A

Compare Array Index
i have two arrays with the same number of index items. the first array contains buttons i have on stage, and the second array contains MovieClips.

i have a function that sets a variable called "activeButton" equal to the last clicked button in the menu.

what i want to do is animate the MovieClip which is contained in the same index of the second array as the currently "activeButton". for example: activeButton = company_btn. the index of company_btn in my first array is [2]. i want to animate the MovieClip in the second array with the index of [2].

is there a way to compare the equality of an index between two arrays? or do i have to get clever with some variables.

thanks
kurt

Array Index Numbers
I'm duplicating a series of movieClips along with a for loop that is populating an array with the instance names of these movieClips.

Is there a way to trace just the index numbers of the array?

I tried a clipEvent function on the actual movieClip that calls for the i variable in the for loop, but it's only returning the last number in the for loop for all the movieClip duplicates.

Variables Within An Array Index
OK, so here I am having tried a bunch of different ways to get this done to no avail...

I'm parsing data from an XML file and I can't seem to get this to work.

In a nutshell, what I'm trying to do is grab a specific piece of an XML entry.

below is my code:


ActionScript Code:
stop();
myXML = new XML();
myXML.ignoreWhite = true;
myXML.load("faq.xml");
myXML.onLoad = function(success) {
    if (success) {
        parseXML(this);
        var i = myId;
        trace(Data[i].answer); // returns undefined
        trace(Data[0].answer); // returns correct information
        trace("i = " + i); // returns the correct variable
    } else {
        trace("fail");
    }
};
function parseXML(xml) {
    _global.Data = new Array();
    aNode = xml.childNodes;
    len = aNode.length;
   
    for (var n=0;n!=len;n++) {
    obj = {};
    obj.question = aNode[n].attributes.question;
    obj.answer = aNode[n].attributes.answer;
    Data[n] = obj;
    }   
}

below is the XML code

Code:
<faq id="0" question="question 1" answer="answer 1" />
<faq id="1" question="question 2" answer="answer 2" />
<faq id="2" question="question 3" answer="answer 3" />
<faq id="3" question="question 4" answer="answer 4" />
<faq id="4" question="question 5" answer="answer 5" />
I've got it working for the most part, but i just can't seem to get the array index to change.

Any help would be appreciated. And thank you for taking the time to answer such a simple question...

Getter With An Array Index?
So, I can do this:

ActionScript Code:
public class Frank {
  public function get mod():String {
    return "hello";
  }
}
And that means I can treat mod as a read-only variable

ActionScript Code:
var blah:String =frank.mod;

But what if I wanted to make a read-only array, like this?

ActionScript Code:
var blah:String=frank.modlist[3];
;
Is this not possible? Is my only solution is to use a function instead?


ActionScript Code:
public function getMod(index:int):String {
...

Getting Array Index Dynamically?
Howdy,
I have multiple arrays such as these:

myArray1[0] = "Some text here";
myArray1[1] = "Some sub text";
myArray1[2] = "More sub text";
myArray1[3] = "Even More text";

myArray2[0] = "Some text here";
myArray2[1] = "Some sub text";
myArray2[2] = "More sub text";
myArray2[3] = "Even More text";

myArray3[0] = "Some text here";
myArray3[1] = "Some sub text";
myArray3[2] = "More sub text";
myArray3[3] = "Even More text";

Now i have multiple text fields that are created dynamically, one as a header, and several below for pages. It looks something like this on stage. Each set of text fields is created from the arrays and number of items in the arrays. Even though i'm showing one, three will be created.
HeaderField
subPageField
subPageField
subPageField

So here's what i want to do... I want to use the Array indexes to fill in the text fields. For example, Index [0] would fill in the HeaderField. Indexes [1]-[3] wold fill in the sub pages. I want to do this dynamically and not hard code them.
How can i pull out each Index dynamically to fill in the text fields??

Ideas or suggestions would be most helpful.
thx

B

Index Of Array In For-each Loop
Consider an array with x number of elements (of type Object) where some of the elements might be undefined.
I use a for-each loop to access all the elements of the array that is not undefined (since it simply skips the undefined elements).
But. I also want the index of that particular element.

The only option I can see is to use indexOf(). But it feels a bit like looking for water on the other side of the river so to speak.

When looping through long arrays each frame, is there a change indexOf() might slow it down? or does the for-each loop somehow know what index it's dealing with?

Better solutions?

Movieclip Associated With Array Index
Alrighty here is my code:


ActionScript Code:
function setButtons() {    trace (_root["questionArray"+questionNum][0]);    for (i=0; i<=_root["questionArray"+questionNum].length; i++) {        trace (_root["questionArray"+questionNum][i]);        _root["questionArray"+questionNum][i].gotoAndStop(2);    }}setButtons();


so when I trace (_root["questionArray"+questionNum][0]); it comes out as radio1 however the second trace (_root["questionArray"+questionNum][i]); is undefined. Why?

Movieclip Associated With Array Index
Alrighty here is my code:


ActionScript Code:
function setButtons() {    trace (_root["questionArray"+questionNum][0]);    for (i=0; i<=_root["questionArray"+questionNum].length; i++) {        trace (_root["questionArray"+questionNum][i]);        _root["questionArray"+questionNum][i].gotoAndStop(2);    }}setButtons();


so when I trace (_root["questionArray"+questionNum][0]); it comes out as radio1 however the second trace (_root["questionArray"+questionNum][i]); is undefined. Why?

Comparing Array Index
If I wanted to compare the elements of an array with that of the elements of another array to see if the elements of the first should be added to the second...how would I go about that.

I'm thinking using two separate for loops.

Xml > Array > Index Variable WHY CAN'T I DO IT?
For some reason I can "walk the tree" with xml fine and get what i want out of it. When it comes to making an .onRelease function for a dynamically attached mc which relates to the array from the xml however.. i start screwing up somehow.

i've been over and over the problem and can't seem to get a handle on it. it should be simple. i create an index variable and pass that into my function. and still no worky!

what happens is my menu populates but when you click on the button generated by [0] from my array you return the value associated with [1]. Then clicking on the last dyn clip in the menu returns nothing (because it's the last in the array) and all the buttons return incorrect values.

ARRRRGGG!!!! if anyone can help they'd be my hero (for what that's worth).

here's my code:

ActionScript Code:
stop();
holderMc._visible=false;
var columns=1;
var list_spacing = 18;
yamahaList= new XML();
yamahaList.ignoreWhite=true;
 
yamahaList.onLoad=function(success){
    if(success){
       
    trace(this.status);
        atvModels = yamahaList.firstChild.childNodes;
    trace(atvModels);
     for (var i=0; i<atvModels.length; i++) {
         item.index = i;
        
         item = holderMc.attachMovie("listClip", "listClip"+i, i);
         item._x = (i%columns)*list_spacing;
         item._y = Math.floor(i/columns)*list_spacing;
         var atvName = atvModels[i].attributes.name;
         item.atvName=atvName;
         item.atvButton.onRelease=function(){
             var j=this._parent.index;
             var nameatt = atvModels[j].attributes;
            yamahaModel=nameatt.name;
            holderMc._visible=false;
      }
     }
    }
}
yamahaList.load("yamahaATV.xml");

Array - Pop At Index Function
Hi,

I have an array that keeps control over a row of movieclips and the order they are placed in. I now like to be able to drag these around and change the order and the array behind. So far so good. But i cant really get my head around on how to pop in an id at an specific index in a array.
Ex: i have [1,2,3,4] and the i like to drag 2 before 4, i then have to pick out 2, place 2 in 4's old place and push down 3 and 4 to get [1,3,4,2]

How could i do this in a smart way?

I could also be the case that im moving something down the order. Say i have [1,3,4,2] and drag 4 before 1. I then have to pick out 1 and place it before 3...

I'm lost...

Need To Extract { (fieldname: Index) } From An Array.
Variable _level0.songarray = [object #10, class 'Array'] [
0:[object #11, class 'Object'] {
genre:"Trance",
date:"2002_11_21",
name:"Evolution"
},
1:[object #12, class 'Object'] {
genre:"Trance",
date:"2002_12_15",
name:"The_Cloud"
},
2:[object #13, class 'Object'] {
genre:"House",
date:"2002_12_26",
name:"4_AM_Desire"
},

...

I want to extract the "name" field from index "1" as a string.

for example:

code:

this.index = 1;
this.songname = _root.songarray.slice( "name:" add index);




This is the code I used to put it in:

code:

_root.attachitems = function() {
_root.attachMovie("listmc", "listmc", _root.contentdepth)
for (num=0;num<=_root.totalsongs;num++) {
_root.listmc.listpane.attachMovie("listitem", "listitem" add num, num+1);
set ("_root.listmc.listpane.listitem" add num add ".index", num);
setProperty("_root.listmc.listpane.listitem" add num,_y,num*20);
setProperty("_root.listmc.listpane.listitem" add num,_x,5);
}
}
_root.listtoarray = function() {
_root.logthis("listtoarray");
_root.totalsongs = Number(_root.songlist.total);
_root.logthis("last song: " add _root.totalsongs);
_root.songarray = new Array()
for (num=0;num<=_root.totalsongs;num++) {
_root.songarray.push( {name: eval("_root.songlist.name" add num),date: eval("_root.songlist.date" add num),genre: eval("_root.songlist.genre" add num)});
}
_root.logthis(num add " songs added");
}




Thanks in advance.

Finding The Index Number In An Array
Hi there - not sure if this is a tricky one, but hopefully someone can help.

I have an array with a list of ten scores in. I have an object called "details" with a variable attached called "score". I know that details.score is in the array because I just put it in there and had the array sorted using .sort) with a function in the braces to sort numerically rather than by ascii.

Now I want to find out the index number of that score. The reason is that details also has another variable, Name. I also have another array with a list of names in of Top Ten scorers. If a player gets a top ten score, his/her score is put into the score array and sorted. So now I have to find out the position of the new score so that the players name is placed in the same index in Top Ten scorers array.

The reason for all this is that I have a Score board screen where the two arrays are looped through with a For and obviously the two, score and name, have to match.

Now I know I am probably doing this inefficiently and yes I will be exploring later better methods to handle this, but I am new in the area of multiple arrays; so any help would be gratefully received!

cheers

frank

Comparing Array Index Levels
Hey All,

How might I get this to return true.....

range = new Array;

for(i=0; i<10; i++) {
range [i] = (i * 20);
trace(range[i]);
}


position = new Array;

for(b=0; b<10; b++) {
position [b] = (b * -280 + 50);
trace(position[b]);
}

if (position[0] == range[0] ) {
trace("yeah Bouy!!!!");
} else {
trace("naw Dog!");
}


That's to say how can I test that the index position [0] & [0] return as true? Not the values just index position.

-j-

How Can I Access The Value Of An Array Index (or Key) Number?
how can i access the value of an array index (or key) number?

I know how to get the value of the array (large_array[0], but I can't find how get the actual number, i.e., 0, 1, 2, etc. I want to access corresponding values in other arrays, as in: if btn2_mc (of the btn_array [btn0_mc, btn1_mc,...] ) is clicked, it hides redGraphic2_mc (of the redGraphic_array [redGraphic0_mc, redGraphic1_mc, ...]) and so on for other arrays. Using Flash 8...

Thanks!

[F8] Reference An Array By Label, Not Index?
Hi,
is there any way to create a list (any kind of data type, need not be an array) whose members I can reference by a distinct label, rather than an index, as is the case with arrays?
I'd rather not do it via indices, since I'd have the search the entire array and compare strings each time...
I tried creating an object to do this, since I know that I can reference parts of an object by label (i.e.: varName = {label1:"mydata", label2:"mydata"};) but I can't get it to work. I think it's because I'm trying to add those properties (label1 and label2) after I initialize the object, and if that's the case, this isn't going to work, since I need to add elements to the list dynamically, along with their labels.
Help? Please let me know if I've explained this clearly enough

[F8] Reference An Array By Label, Not Index?
Hi,
is there any way to create a list (any kind of data type, need not be an array) whose members I can reference by a distinct label, rather than an index, as is the case with arrays?
I'd rather not do it via indices, since I'd have the search the entire array and compare strings each time...
I tried creating an object to do this, since I know that I can reference parts of an object by label (i.e.: varName = {label1:"mydata", label2:"mydata"};) but I can't get it to work. I think it's because I'm trying to add those properties (label1 and label2) after I initialize the object, and if that's the case, this isn't going to work, since I need to add elements to the list dynamically, along with their labels.
Help? Please let me know if I've explained this clearly enough

(p.s. if anyone notices I posted this in the newbies section too, I apologize... posted there first and realized this is a more appropriate place for it)

[F8] How Do I Find The Index (key) Of A Specific Value In An Array?
Hello All,
Is there a way to retrieve a specific element's index key if you only know the value of the element?
Usually, you give Flash an index ([0], [1], [2]...) and it gives you the value of the element at that position. I would like to do the inverse, because I know what the values of the array will be... however, they could be in any order.

Example:
myArray_array("Chris", "Mike", "Fred", "Jen", "Susan")

I want to remove "Fred" from the array; however, I don't know Fred's index key... and he could be anywhere in the array. Also, after removing "Fred", I do NOT want the array to contain an "undefined" or "empty" element where "Fred" used to be:

BAD:
myArray_array("Chris", "Mike", undefined, "Jen", "Susan")

GOOD:
myArray_array("Chris", "Mike", "Jen", "Susan")

Thanks!

Getting An Error When I Try To Use HitTestObject On An Array Index?
This is the error I get:

TypeError: Error #1034: Type Coercion failed: cannot convert Enemy$ to flash.display.DisplayObject.
at Keepaway/onLoop()

Here are all the class's variables:

Code:
private var numEnemies:int = 15; //this is the number of enemies
private var sizeIncrease:Number = 10; // how much bigger to make each enemy. bigger number = bigger scale
private var enemyX:Number = stage.stageWidth/2; // where enemies start
private var enemyY:Number = stage.stageHeight/2; // where enemies start
private var speedMultiplier:Number = 10; // higher = faster
private var speedMin:Number = 5; // this is the minimum speed allowed
private var theBackground:Background = new Background; //cover the stage with a background rectangle
var lag:Number = 20; // hero lag (higher = more sluggish)
var enemyArray:Array = new Array();
var hero:MovieClip = new Hero();


This is the function with the problem. It makes the symbol Hero follow the cursor around with some lag. I want to detect if the hero hits any of the enemy objects, which are all in enemyArray.


Code:
//make hero follow cursor
function onLoop(evt:Event):void {
evt.target.x += velFriction(evt.target.x, mouseX, lag);
evt.target.y += velFriction(evt.target.y, mouseY, lag);

//test all enemies for overlap
for(var i:int = 0; i < enemyArray.length; i++) {

if(hero.hitTestObject(enemyArray[i])) {
trace(hero.x);
}

}


}
For some reason the hitTestObject isn't working right on enemyArray[i]. Can anyone see my problem??

Thanks!

Trouble Finding An Index Of An Array
Hi all,
I have posted this on the adobe forum and have got closer and closer to making this work.
I have parsed data from a CSV file and got it into an array. However when I try and find an index of an array, I am getting an undefined returned.

Code:
stop();
Array.prototype.findPos = function(value) {
var tAr = [];
for (var i = 0; i<this.length; i++) {
if (this[i] == value) {
tAr[tAr.length] = i;
}
}
return (tAr.length>0) ? tAr : false;
};
myVars = new LoadVars();
myVars.load("members.csv");
myVars.onData = parseCSV;
var TonyData = [];
function parseCSV(raw) {
var delim = (raw.indexOf("
") > -1) ? "
" : (raw.indexOf("
") > -1) ? "
" : "
";
var temp = raw.split(delim);
var fields = temp.shift().split(",");
for(var i=0;i<temp.length;i++) {
var row = temp[i].split(",");
if(row.length != fields.length) continue;
var tmpObj = {};
for(var j=0;j<row.length;j++) {
tmpObj[fields[j]] = row[j];
}
TonyData.push(tmpObj);
}
TonyData.onData
trace("Data Has Loaded");
trace("33's trace is..." + TonyData[33].Name_First + " " + TonyData[33].Name);
trace("10's trace is..." + TonyData[10].Name_First+" "+TonyData[10].Name);
var finder
//This finder value actually works, but introducing findPos causes it to fail finder = TonyData[10].ID;
finder = TonyData[10].ID.findPos(42703);
trace(finder);
if (!finder) {
trace("not found");
} else {
trace("The Array Index relating to the Membernum is: " + finder);
}
gotoandstop(2);
};
The annoying thing is that I can trace TonyData[10].ID but TonyData[10].ID.findPos returns undefined. I have also tried getIndex as well with the same results.
Does anyone have any experience in getting an index of a CSV parsed array, or can anyone see any holes in this code?
Any help would be greatly appreciated.
Regards,
Tony

Indexed Array Always Beging At Index '0'?
Ok so I'm passing arrays from PHP to AS3 and I one array in PHP starts at index 1,2,3,...,24 (the hours in a day) so the array look like this:


Code:
array('1' => '1:00 AM', '2' => '2:00 AM', '3' => '3:00 AM', '4' => '4:00 AM', '5' => '5:00 AM', .......................)
But it seems that AS3 adds an index at the beginning "0" => "" (its adding an index 0 at the beginning poinint to nothing or null not sure).

Am I crazy? What I am doing is setting the times above in a List component and its a multiselect to select various times. I try to create an array with the key values from the chosen user values to send back to php so if the user selected 1am and 2am above the array I want to return to PHP should look like this:


Code:
array('1' => '1:00 AM', '2' => '2:00 AM')
BUT AS3 adds that index of '0' AGAIN returning the following:


Code:
array('0' => '', '1' => '1:00 AM', '2' => '2:00 AM')
but I know that the loop where I create that array only iterates TWICE. Again, am I going crazy???

Thanks!

Array With Multiple Values In An Index?
I'm using Flex 2 and I want to store data in an Array, but more than one value in each index .. is that possible?

For example instead of an Array like:

arrayName[0] = "word";
arrayName[1] = "word1";
arrayName[2] = "word2";

I want "properties I guess in each index:

arrayName[0] = name="word", id=22, boo=true;
arrayName[1] = name="word1", id=172, boo=false;
arrayName[2] = name="word"2, id=98, boo=true;

Insert Into Array At Specific Index?
Is there a way to push() a value to an Array but at a specified index?

Thanks!

Arrays || Dynamic Array Name & Set Index
Hi, I have been searching through the forums and could not find anything regarding my dilemma.

I created a three stage break down of a mass string into arrays the second array

set("display_info_"+x, info_split[x].split("*"));

breaks information incrementally into
display_info_0
display_info_1
display_info_x

This works and the "display_info_x" is populated with the correct data.

Now here is the problem I am facing. I need to populate a new array lets say it is:

batch_list = new array()

with

display_info_{x}[2]

I have written this to display what I am trying to achieve, this is a non-working setup but should give you an idea of what I am talking about.

batch_list[x] = eval("display_info_"+x+"[2]");

This is looped through and stops according to x amount of "display_info_x", this is not that important (the looping) mainly I need to know if there is a way to an array name called dynamically.


Thank for your help...

RD

Finding The Position Of An Array Index
i was wondering if you have an array value, can you find what number it is in the array's order. For example,

letters=new Array("a","b","c","d");
cnumber=letters.position["c"]
trace(cnumber);

so that cnumber=2. How would I go about doing something like this?

-Brendan

How To Retrive The Index Value Of The Emements In An Array
hey ppl

I'm wondering is there a way to check the index of the item in an array
my array:Array=["one", two, "three", "four"]

can i some how get the index value of the elements inside the array


Tnx in advance.

Shom

Finding Index Of Array Item
I'm working in AS2 and have created an array of movie clips (symbol_box[n]) with n ranging from 0 to 24. I want to be able to return the index of a movie clip (symbol_box[n]) when it is clicked so I can use it to access another movie clip in a second array. I need to be able to get the value of n... i.e. the index of the clicked clip. Any ideas? I'm sure it is simple!

Returning Index Array Problem
Hello,

how can this happen? I am creating a deck of cards and populating its array with 48 cards. When I use the RETURNINDEXEDARRAY method I become short of 4 cards.

Here's my script(someone try it):

function init() {
deck= new Array();
for (var suit = 0; suit<=3; suit++) {
for (var i = 0; i<=11; i++) {
do {
var deckpos = Math.round(Math.random()*47);
} while (deck[deckpos] != null);
deck[deckpos] = String(suit)+String(i);
}
}
}
init();
trace(deck);
var player:Array = deck.sortOn("0", Array.RETURNINDEXEDARRAY);
trace(player);

Dynamic Array Index Names
I'm creating an extension of the DataProvider class that receives XML and converts it to a DataProvider automatically. This will simplify sorting XML and binding it to acceptable objects, like a DataGrid.

Where I'm stuck is creating a dynamic array with index names matching the node names. Here's what I have:

Code:
//get the column names
for(var i=0;i<xml[0].children()[0].children().length();i++){
xmlColumns.push(xml[0].children()[0].children()[i].name());
}
//populate the dataprovider
for(i=0; i < xml[0].children().length(); i++){
var currentNode = xml[0].children()[i];
var currentArray = new Array();

for(var m=0; m < xmlColumns.length; m++){
var nodeName:String = currentNode.children()[m].name();
currentArray.push({nodeName:currentNode.children()[m]});
}
trace(currentArray);
this.addItem(currentArray);
}
Notice the nodeName variable I am trying to use as the alias for the columns. I've tried this several ways:


Code:
currentArray.push({nodeName:currentNode.children()[m]});
currentArray.push({this[nodeName]:currentNode.children()[m]});
currentArray.push({String(nodeName):currentNode.children()[m]});
currentArray.push({nodeName.toString():currentNode.children()[m]});
currentArray.push({$nodeName:currentNode.children()[m]});
currentArray.push({%nodeName%:currentNode.children()[m]});
currentArray[m][nodeName]=currentNode.children()[m];
I think I'm going to kick myself when I found out what to do here, but quite a few google searches have not yielded much either...

I really appreciate any help.

Thanks,
Stephen

Length Of An Array With String Index
You can find the length of an array through the property length (e.g. arrayInstance.length)

But I realize that I cannot use this property if I specify the array index through strings
for example:


Code:

var arrayInstance = new Array();
arrayInstance["cat"] = "Garfield";
arrayInstance["dog"] = Jazzy Dog";
arrayInstance["mouse"] = "Mickey Mouse";
trace(arrayInstance.length) //returns 0 !!

Index Number Of Array Element
Hello all,

How does one find out the index number of a particular element in an array.

Say i have an array named fruit and it is populated with the following five fruits in this order: apple, banana, orange, pear and mango.
If for one reason or another i happen to be dealing with the element/value orange, using actionscript, how can i determine that its index number is 2.

Many Thanks.

Updating An Array's Index Values
okay, this is killing me, I don't have the patience to sit here and toy with this anymore.  Hopefully somebody out there can help me with this...

I have an array of mcs, I want to pass a random grouping of them to a function on the press of a button, I have this sitting in the first frame of my movie:

//variables

arraySize = 30        
randomNumber = 0;    

//functions

function prep (player) {
    player._alpha=33;
};

function scaleup (player) {
    player._alpha=100;
    player._xscale=200;
    player._yscale=200;
};

function scaledown (player) {
    player._alpha=33;
    player._xscale=100;
    player._yscale=100;
};

//arrays

playerArray = new Array (_root.a1, _root.a2, _root.a3, _root.a4, _root.a5, _root.a6, _root.a7, _root.b1, _root.b2, _root.b3, _root.b4, _root.b5, _root.b6, _root.b7, _root.c1, _root.c2, _root.c3, _root.c4, _root.c5, _root.c6, _root.c7, _root.d1, _root.d2, _root.d3, _root.d4, _root.d5, _root.d6, _root.d7, _root.e1, _root.e2, _root.e3, _root.e4, _root.e5, _root.e6, _root.e7);

booleanArray = new Array (_root.arraySize);    

I then have this on the button:

on (release) {
    randCount = random (_root.arraySize - 1);
    for (j=0; j < randCount; j++) {
        _root.randomNumber = random(_root.arraySize - 1);
        if (booleanArray[_root.randomNumber] != true) {
            booleanArray[_root.randomNumber] = true;
        }
        else {
        j--;
        }
    };
    for (q=0; q < _root.arraySize; q++) {
        if (booleanArray[q] == true) {
            _root.novis(movieclipArray[q])
        }
    };
    for (k=0; k < (_root.arraySize - 1); k++) {
        booleanArray[k] = false;
    }
}

when I debug the movie, I see the variables randCount and randomNumber updating, but the index values of booleanArray don't update.  Anybody got any ideas?  

tia
bugg


Copyright © 2005-08 www.BigResource.com, All rights reserved