# Loading actionscript at runtime

**URL:** <https://forum.kirupa.com/t/loading-actionscript-at-runtime/6753>\
**Category:** flash\
**Created:** [October 15, 2002, 7:24pm UTC](https://forum.kirupa.com/t/loading-actionscript-at-runtime/6753 "2002-10-15T19:24:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![yellowjacket](https://avatars.discourse-cdn.com/v4/letter/y/f05b48/32.png) [@yellowjacket](https://forum.kirupa.com/u/yellowjacket)\
**Post date:** [October 15, 2002, 7:24pm UTC](https://forum.kirupa.com/t/loading-actionscript-at-runtime/6753/1 "2002-10-15T19:24:04Z")

</div>

I am trying to load a text file that contains 125 objects that can change each time the movie is run. The objects are in the object initializer format of object {name1: value1…name4: value4}; and are part of my actionscript.

I can load the file with no problem and view them in a scrolled text window but I don’t know how to convert them to actionscript as they would be if I used #include to load the file.

Any ideas?

Yellowjacket

---

<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 15, 2002, 7:58pm UTC](https://forum.kirupa.com/t/loading-actionscript-at-runtime/6753/2 "2002-10-15T19:58:55Z")

</div>

if it will work using include file, why are you trying to load them into variables? Just curious.

---

<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 15, 2002, 9:17pm UTC](https://forum.kirupa.com/t/loading-actionscript-at-runtime/6753/3 "2002-10-15T21:17:14Z")

</div>

#include loads the file at compile time so once you have published the movie you can not change it. It want to change the  
movie each time it runs

Yellowjacket

---

<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 15, 2002, 10:34pm UTC](https://forum.kirupa.com/t/loading-actionscript-at-runtime/6753/4 "2002-10-15T22:34:02Z")

</div>

one way…

since flash will only import strings, so you could put them all in a string delimited by whatever characters (in this case “,” and “:”).

so in your text file (myVars.txt):

```auto

objStr = obj1:value1,obj2:value2,obj3:value3

```

then in the fla, load that string, and parse it into an object by splitting the string by whatever characters:

```auto

content = new LoadVars();
content.onLoad = function(){
	this.obj = {};
	var i,b,a = this.objStr.split(",");
	for(i in a){
		b = a*.split(":");
		this.obj[b[0]] = b[1];
	}
}
content.load("myVars.txt");

```

that will put all the pairs in \_root.content.obj.

---

<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 16, 2002, 2:29am UTC](https://forum.kirupa.com/t/loading-actionscript-at-runtime/6753/5 "2002-10-16T02:29:24Z")

</div>

good to see you Supra!
