PDA

View Full Version : Dynamic LoadVars items


MicroSun
04-24-2006, 09:53 PM
Hello,

I create a flash form which contains TextInput components. The number, position, name, label of these compnents are defined in an XML file. With actionscript I process the XML and create new components and put them in an array.
Everything works fine except that I can't find a good way to send user inputs to a php script. If I collect the values in an array and pass it to loadvars than it converts the array to a comma separated string. But what if the user enters a comma in the textfield. I want to allow this but in this case I can't rebuild the array in PHP. See my submit code below.

How can I solve this problem?

Thanks!


function submit() {
var tt = new Array();
tt[0] = testBoxes[0].text;
tt[1] = testBoxes[1].text;
tt[2] = testBoxes[2].text;
userData = new LoadVars();
userData.out = tt;
userData.send("form.php", "", "post");
}

CyanBlue
04-24-2006, 10:09 PM
Howdy and Welcome... :)

I think you will need to specifically specify what variables to send to PHP script rather than just saying 'userData.out = tt;', so it'd be something like this...
userData.out0 = tt[0];
userData.out1 = tt[1];
userData.out2 = tt[2];That'll pass $_POST['out0'], $_POST['out1'], $_POST['out2'] to the PHP script...

MicroSun
04-24-2006, 10:25 PM
Hello CyanBlue,

unfortunately I can't use this specific assignment, because in my example there were 3 items in the testBoxes array, but the array can hold any number of items as defined in XML. (Sorry, my example is not the best as it use hardcoded item numbers and not a loop to fill variables.)

Maybe it is not possible with loadvars, but is it possible on any other way?

Thanks!

CyanBlue
04-24-2006, 10:49 PM
How about creating those variables dynamically depending on the number of nodes in your XML file???

MicroSun
04-25-2006, 06:14 AM
How about creating those variables dynamically depending on the number of nodes in your XML file???

I have the following code to do this:

function processForm(xmlFile){
var x:Number = 0;
var y:Number = 0;
var name = "";

for (var n = 0; n<xmlFile.firstChild.childNodes.length; n++) {
x = Number(xmlFile.firstChild.childNodes[n].attributes.x);
y = Number(xmlFile.firstChild.childNodes[n].attributes.y);
name = xmlFile.firstChild.childNodes[n].attributes.name;

testBoxes[n] = attachMovie("TextInput", name, 10+n);
testBoxes[n]._x = x;
testBoxes[n]._y = y;
}
}