Groups | Blog | Home
all groups > flash actionscript > may 2005 >

flash actionscript : Loaded variables


teamtoast
5/29/2005 9:34:42 PM
Hello. I'm having trouble using the variables I have loaded.

I don't have any trouble loading variables and having them show up where they
should. ie loading text into a textfield. I figured i should be able to use
those variables in my actionscript as well. They are showing up as undefined
like they are out of scope (i'm a C++ guy to start)

I want to load a list of locations from the list file. for each i want to
place a link button labelled with that name on the movieclip. Then each of
these buttons will load a new set of variables to put into another frame.

So that's the plan. If you're going to take this lttle baby on I would greatly
appreciate you pointing out where my logic has gone wrong. I'd like to be able
to do this myself next time.


//---- beginning of code
loadVariables("list.txt", this, "GET");

//list.txt contains num=2&loc1=Seebee&loc2=Elko

for(var count = 1; count <= parseInt(num) ; count++){
var currentname = "loc" + count
trace( currentname); //outputs "loc1" not Seebee like I want
var holder = this.attachMovie("buttonholder", "buttonholder"+count , i)
holder._x = 5
holder._y = 5 + 40*count
holder.button.labelname = currentname
//
holder.button.onRelease = function () {
loadVariables(currentname + ".txt" , this, "GET");
};
//

}

//-----------end of code
kglad
5/29/2005 9:49:24 PM
first, you shouldn't execute any code that depends upon loaded variables until
the variables have completed loading. your for-loop will complete long before
loading even starts. you can use the onData handler.

second, you'll need to instruct flash to interpret your strings as objects
using brackets (or sometimes the eval() function):

currentname=this["loc"+count]; /* <-currentname contains a reference to an
object, the variable "loc"+count */

or

currentname="loc"+count; /* currentname contains a string and you can use
this[currentname] to have flash interpret that string as an object.

and finally, you button is going to remember which button it is after your
for-loop variable increments. by the time any of your buttons are pressed they
are going to be referencing the last value store in currentname. you need to
assign a variable to each button to store its count-value. for example:

holder.button.countVar=count

teamtoast
5/29/2005 9:52:12 PM
Thank you, I'll get to work on that
kglad
5/29/2005 9:55:25 PM
you're welcome. if you have any problems, let us know.

i left some details for you to figure out and help you learn, but it's hard to
know when i'm spoon-feeding more than needed or leaving out so much that it's
frustrating .
AddThis Social Bookmark Button