Loading actionscript at runtime

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?


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

#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


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):

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:

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];

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

good to see you Supra!