# \[FMX\] String to Array

**URL:** <https://forum.kirupa.com/t/fmx-string-to-array/42856>\
**Category:** flash\
**Created:** [February 13, 2004, 6:48pm UTC](https://forum.kirupa.com/t/fmx-string-to-array/42856 "2004-02-13T18:48:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![foochuck](https://avatars.discourse-cdn.com/v4/letter/f/dfb087/32.png) [@foochuck](https://forum.kirupa.com/u/foochuck)\
**Post date:** [February 13, 2004, 6:48pm UTC](https://forum.kirupa.com/t/fmx-string-to-array/42856/1 "2004-02-13T18:48:29Z")

</div>

Hello,

(Using Flash MX)

I’m wondering if theres a way I can turn a variable of strings (separated by commas) into an array?

I’m using the loadVars object to import variables from a text file that I’d like to import to flash as an array.

For example if the variable I import from the text file looks like this:

&myVar=charlie,dog,cat,test&

I’d like to get it into an array in Flash like this

myArray = new Array[“charlie”,“dog”,“cat”,“test”];

Is there any way to do that? :rocker:

Thanks!

---

<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:** [February 14, 2004, 2:24am UTC](https://forum.kirupa.com/t/fmx-string-to-array/42856/2 "2004-02-14T02:24:19Z")

</div>

You will need the asfunction to load the movies from the text links.  
Check this:  
[http://www.kirupaforum.com/forums/showthread.php?s=&threadid=42654](http://www.kirupaforum.com/forums/showthread.php?s=&threadid=42654)

---

<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:** [February 14, 2004, 3:30am UTC](https://forum.kirupa.com/t/fmx-string-to-array/42856/3 "2004-02-14T03:30:13Z")

</div>

caludio - thanks thats just what I needed.

One problem though, I’m using the comma (",") as my delimiter for splitting the variable that I’m importing and when the comma shows up in this line of code:

```auto

&cats=<a href='asfunction:listing,adv'>Advertising Agencies</a>

```

It cuts off the asfunction - function and argument and just plain out messes up my string.

Is there another delimiter I can use besides a comma, a white space or a tab?

---

<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:** [February 14, 2004, 3:34am UTC](https://forum.kirupa.com/t/fmx-string-to-array/42856/4 "2004-02-14T03:34:27Z")

</div>

You can use any symbol.

---

<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:** [February 14, 2004, 3:52am UTC](https://forum.kirupa.com/t/fmx-string-to-array/42856/5 "2004-02-14T03:52:31Z")

</div>

I have a better idea. It would be better to use XML, but heres an optimized version:

```auto
function loadClip(arg) {
	var temp = arg.split("|");
	loadMovie(temp[0], temp[1]);
}
l = new LoadVars();
l.onLoad = function(success) {
	if (success) {
		my_txt.html = true;
		var myArray = this.myVar.split(",");
		for (var i = 0; i<myArray.length; ++i) {
			var parameters = myArray*.split("|");
			my_txt.htmlText += "<b><font size='14'><a href='asfunction:loadClip,"+parameters[0]+".swf|"+parameters[1]+"'>"+parameters[0]+"</a></font></b>
";
		}
	}
};
l.load("textfile.txt");

```

and your textfile should hold the file name and the corresponding container movieclip:

```auto
myVar=dog|holder1,plane|holder2,cat|holder3,house|holder4&

```

---

<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:** [February 14, 2004, 3:52am UTC](https://forum.kirupa.com/t/fmx-string-to-array/42856/6 "2004-02-14T03:52:53Z")

</div>

Alright I’m using the # sign and that works fine.

Now I have another question :jail:

The items in the array I’m importing now look like this:

```auto

<a href='asfunction:listing,0'>Advertising Agencies</a>

```

I’d like to somehow turn this item from my array back into a variable without the HTML tags around it so it will just look like

Advertising Agencines

And then I’d like to break that down into just a 4 letter variable starting with the first 4 characters

adve

I know that I can use split() on the string as well as toLowerCase() on the last two items, but how can I get rid of the HTML Tag first off?

Thanks!

---

<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:** [February 14, 2004, 4:08am UTC](https://forum.kirupa.com/t/fmx-string-to-array/42856/7 "2004-02-14T04:08:58Z")

</div>

Claudio,

Thanks for your ideas they are really helping me. I owe you 2.

Foo

---

<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:** [February 14, 2004, 4:12am UTC](https://forum.kirupa.com/t/fmx-string-to-array/42856/8 "2004-02-14T04:12:06Z")

</div>

welcome foo 😉
