# Multidy arrays and objects

**URL:** <https://forum.kirupa.com/t/multidy-arrays-and-objects/5807>\
**Category:** Uncategorized\
**Created:** [September 22, 2002, 4:16pm UTC](https://forum.kirupa.com/t/multidy-arrays-and-objects/5807 "2002-09-22T16:16:43Z")\
**Posts on this page:** 15\
**Page:** 2

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 23, 2002, 6:42am UTC](https://forum.kirupa.com/t/multidy-arrays-and-objects/5807/21 "2002-09-23T06:42:58Z")

</div>

_bowing down to jsk_

Thanks man. You totally rock.

pom 🙂

Can anyone rate this thread? I’d like to put it in the Best of Kirupa when we’re done with this…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 23, 2002, 7:03am UTC](https://forum.kirupa.com/t/multidy-arrays-and-objects/5807/22 "2002-09-23T07:03:30Z")

</div>

I rated it a 5. Definitely educational!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 23, 2002, 11:26pm UTC](https://forum.kirupa.com/t/multidy-arrays-and-objects/5807/23 "2002-09-23T23:26:34Z")

</div>

this is definitely one of the better threads - learned tons… and tons - thanks everyone!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 24, 2002, 12:10am UTC](https://forum.kirupa.com/t/multidy-arrays-and-objects/5807/24 "2002-09-24T00:10:17Z")

</div>

thanks, you’re very kind.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 24, 2002, 12:56am UTC](https://forum.kirupa.com/t/multidy-arrays-and-objects/5807/25 "2002-09-24T00:56:15Z")

</div>

ohhhhh here we go again folks…stuck on one part and only one part - jks - if you have insight let me know!!

After shifting and splitting - i need to use those vars to populate a listbox. I got this working. However, I need to do it in a loop and my loop keeps screwing up - so it doesn’t populate correctly:

CODE:  
//-----------------------  
function convertString(){

```
tempArray=theRecoveredString.split("#");
thisVar=tempArray.length;
for(i=0;i&gt;=thisVar;i++){
  myPair=tempArray.shift();
myPairDone=myPair.split("|");
  	_root.message=tempArray.length;
   k=myPairDone[0];
     m=myPairDone[1];
   	allSongs.addItemAt(i,k,m);
	t_obj=k.concat("|",m);
	playlist=new Array();
	playlist.push(t_obj);
	delete t_obj;

```

}  
}

//----------------------------------  
okay I know the problem is that since i am shifting elements out of the array - the size of the array gets smaller - changing the whole tempArray.length bit in the loop -----

// – i put the vars into an array again at the end - so that I am reading to go when I need to join them again…I also used # and | delimiters -

Anyhow -its being a bit of a wanker tonight… keeps outputting the first set of vars and that is it.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 24, 2002, 1:07am UTC](https://forum.kirupa.com/t/multidy-arrays-and-objects/5807/26 "2002-09-24T01:07:50Z")

</div>

Hmmm judging by that language you must be in the UK.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 24, 2002, 1:15am UTC](https://forum.kirupa.com/t/multidy-arrays-and-objects/5807/27 "2002-09-24T01:15:58Z")

</div>

actually no -  
i’m from canada.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 24, 2002, 1:20am UTC](https://forum.kirupa.com/t/multidy-arrays-and-objects/5807/28 "2002-09-24T01:20:27Z")

</div>

Really? A universal expression then.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 24, 2002, 2:50am UTC](https://forum.kirupa.com/t/multidy-arrays-and-objects/5807/29 "2002-09-24T02:50:24Z")

</div>

hey all.

i’m a latecomer to this thread but i wrote some code i thought i’d post anyway…

flex - canada loves: black adder, monty python, absolutely fabulous, red dwarf, etc. thus “wanker” is well entwined in our lexicon. so funny… : ) can’t speak for other nationalities.

mediachick - where in canada?

i love putting things in arrays too. these functions are designed to grab an array of objects containing any number of name / value pairs and turn it into a string where:

- objects are seperated by “|”
- name / value pairs are seperated by “,”
- and name is seperated from value by “:”

and extract it back again, of course.

(ps. put your code in [code] tags for formatting)

```auto

function saveDataToString(objArray){
	var i,j,saveString;
	for(i in objArray){
		for(j in objArray*){
			saveString += j + ":" + objArray*[j] + ",";
		}
		saveString = saveString.slice(0,-1);
		saveString += "|";
	}
	saveString = saveString.slice(0,-1);
	return(saveString);
}

function retrieveDataFromString(save){
	var i,j,o,a,b,c,returnedArray = [];
	a = save.split("|");
	for(i in a){
		o = {};
		b = a*.split(",");
		for(j in b){
			c = b[j].split(":");
			o[c[0]] = c[1];
		}
		returnedArray.push(o);
	}
	return(returnedArray);
}

```

a caveat for using for in loops - if you’ve defined custom methods they will appear in your for in loops! ie. if you’ve written a cool Array.prototype.spliceIntoArray() method, when you iterate through an array using for in, spliceIntoArray will be iterated over as if it were in the array.

this can break things. the solution is to hide your custom methods using ASSetPropFlags().

for more info, check [the wiki](http://chattyfig.figleaf.com/flashcoders-wiki/index.php?ASSetPropFlags)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 24, 2002, 7:16am UTC](https://forum.kirupa.com/t/multidy-arrays-and-objects/5807/30 "2002-09-24T07:16:30Z")

</div>

I was wondering, Supra, instead of hiding the method, you could also test the type of the data you get from your for in loop, no? Just wondering.

pom :asian:

And red dwarf… Come on people…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 24, 2002, 12:02pm UTC](https://forum.kirupa.com/t/multidy-arrays-and-objects/5807/31 "2002-09-24T12:02:17Z")

</div>

sbeener -  
I think you just explained and solved my issues with the ASSetPropFlags–  
So if I have any type of extension prototype(Array.prototype.splitIt - lets say or whatever) - its going to show up in any “for In” loop that I do relating to that object ( array)?

I am going to check the wiki! I’ve read about it but never really got it-

So if made objects much like :  
function createNew =function(name,id){  
this.name=name;  
this.id=id;  
}

// and then added those to an array –  
myArray=new Array();  
temporary\_Obj=new createNew(“wanker”,“01”);  
myArray.push(temporary\_Obj);  
delete temporary\_Obj;

//-----------------

This wil be good enough to use the functions you wrote beautifully to convert the object array to a string and then parse it back to an obj array?

Anyone have any pros and cons regarding using obj arrays ? I personally love them…

I’m from the capital - by the way. And yeah, its pretty sad, but english humour really does rule up north…I love absolutely fabulous…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 24, 2002, 4:54pm UTC](https://forum.kirupa.com/t/multidy-arrays-and-objects/5807/32 "2002-09-24T16:54:58Z")

</div>

ily - yeah, sure you can test each time. it’s just not really as elegant, imho.

mediachick - yup, should do the trick. all the functions need is for the objects in the array to contain only name / value pairs - ie. not other objects or arrays. let me know how it goes.

to shorten your code, you can add an object straight to an array like this:

```auto

myArray.push(new createNew("wanker","01"));

```

the array must exist before hand. you can create and populate an array in one step like this:

```auto

myArray = [new createNew("wanker","01")];

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 25, 2002, 12:44pm UTC](https://forum.kirupa.com/t/multidy-arrays-and-objects/5807/33 "2002-09-25T12:44:34Z")

</div>

Hi Mediachickie - typical … I go away for a few days and miss out on all the fun stuff…  
Seems like sbeener has you well sorted (if you’ll excuse a dreadful pun).  
As regards pros and cons of using obj arrays my pingin rua in ActionScripting is that the simplest correct answer (i.e. the one that requires the fewest calculations and thus places the least load on the processor) is always the correct answer - and the easiest one to fix/modify/improve.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 25, 2002, 2:50pm UTC](https://forum.kirupa.com/t/multidy-arrays-and-objects/5807/34 "2002-09-25T14:50:06Z")

</div>

jsk - yeah I would have to agree - whatever allows for expansion-and has the least amount of calculations should be the winner. I have learned tons thos about string manipulation through this thread - more than I think that I ever want to learn… 🙂

if you have a chance , jsk, could you look over the code I posted a couple of postings back in this thread - my loop is all wanky and i would really like to know how to do it – 🙂

i hope we can continue starting and creating threads like this one…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 18, 2002, 6:38am UTC](https://forum.kirupa.com/t/multidy-arrays-and-objects/5807/35 "2002-10-18T06:38:31Z")

</div>

hi…anyone has an example of the \*.fla file? thanx. 🙂

[Previous page](https://forum.kirupa.com/t/multidy-arrays-and-objects/5807.md?page=1)
