LoadVariablesNum (Flash MX)

Hi all,

I’m making a game and I need to load variables into my flash movie from a database. I’m using asp and i know it works fine becuase it outputs what I want.

My problem is that when I try to load the data into flash, it won’t let me use the variables. If I put a dynamic textfield on the stage with fname (one of my variables), the text field diplays the correct data, but when I say trace(fname) with having the text field, “undefined” pops up.

How can I solve this?

  • Ian

trace(fname.text);

:slight_smile:

Thanks for the reply, but that is not working. I’ll give a bit more information:

It’s a Mr. Potato Head and this is for the function that lets people view heads from a database that other people have submitted. You can see it at http://www.snailgames.tk/games/potatohead.

The ASP file outputs in this format: tname=Ian&tpname=eye2|mouth4|nose3&tpx=172|169|160&tpy=143|297|215&tpxscale=100|100|100&tpyscale=100|100|100&tprotation=0|0|0

This is the Action Script in the main timeline so far:

[INDENT]stop();

loadVariablesNum(“viewHead.txt”, 0);

for (i = 1; i <= CountParseString(vpartname, “|”); i++) {
_root.attachMovie(ParseString(tpname, “|”, i), “part” + i, i);
_root[“part” + i]._x = ParseString(tpx, “|”, i);
_root[“part” + i]._y = ParseString(tpy, “|”, i);
_root[“part” + i]._xscale = ParseString(tpxscale, “|”, i);
_root[“part” + i]._yscale = ParseString(tpyscale, “|”, i);
_root[“part” + i]._rotation = ParseString(tprotation, “|”, i);
}

function CountParseString(str, char) {
temp = 1;
for (f = 0; f <= str.length; f ++) {
if (str.charAt(f) == char) {
temp ++;
}
}
return(temp);
}
function ParseString(str, char, section) {
temp = 1;
str = str + “|”;
for (f = 0; f <= str.length; f ++) {
if (temp == section) {
temp = “”;
for (g = f; g <= str.length; g++) {
if (str.charAt(g) != char) {
temp += str.charAt(g);
} else {
return(temp);
}
}
}
if (str.charAt(f) == char) {
temp ++;
}
}
}[/INDENT]

In that for loop, it takes the variables it is supposed to be getting, and uses them to attach the face features and give them _x, _y etc. CountParseString is a function that returns the sections in str separated by char. ParseString is a function that returns the value of section in str separated by char.

I hope this helps.

I found a thread on this that solved my problem: http://www.kirupaforum.com/forums/showthread.php?t=31032

I changed:

loadVariablesNum(“viewHead.txt”, 0);

for (i = 1; i <= CountParseString(vpartname, “|”); i++) {
_root.attachMovie(ParseString(tpname, “|”, i), “part” + i, i);
_root[“part” + i]._x = ParseString(tpx, “|”, i);
_root[“part” + i]._y = ParseString(tpy, “|”, i);
_root[“part” + i]._xscale = ParseString(tpxscale, “|”, i);
_root[“part” + i]._yscale = ParseString(tpyscale, “|”, i);
_root[“part” + i]._rotation = ParseString(tprotation, “|”, i);
}

to:

lv = new LoadVars()
lv.onLoad = function(success) {
if(success) {
for (i = 1; i <= CountParseString(this.tpname, “|”); i++) {
_root.attachMovie(ParseString(this.tpname, “|”, i), “part” + i, i);
_root[“part” + i]._x = ParseString(this.tpx, “|”, i);
_root[“part” + i]._y = ParseString(this.tpy, “|”, i);
_root[“part” + i]._xscale = ParseString(this.tpxscale, “|”, i);
_root[“part” + i]._yscale = ParseString(this.tpyscale, “|”, i);
_root[“part” + i]._rotation = ParseString(this.tprotation, “|”, i);
partnumber = i;
}
}
}
lv.load(“viewHead.txt”)

Yeah I stopped using loadVariablesNum.

You should read this tutorial http://www.flash-db.com/Tutorials/loading/loadingData.php?page=1

It’s real good and gets into a lot fo detail on how it works with both ASP/PHP.

I finished the game!

If anyone wants to see it, you can find it at http://www.snailgames.tk/games/potatohead