Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php + flash , using new LoadVars()

Status
Not open for further replies.

melnet

Programmer
Jul 8, 2003
77
HK
hello~
php code:
for ($i=0;$i<$sql_row;$i++)
{
echo "question$i=".mssql_result($sql_query, $i, "questionName")."&";
echo "answer".$i."1=".mssql_result($sql_query, $i, "answer1")."&";
echo "answer".$i."2=".mssql_result($sql_query, $i, "answer2")."&";
echo "answer".$i."3=".mssql_result($sql_query, $i, "answer3")."&";
}

flash code:
for (a=0; a<=this.total; a++) {
_root.test2 = this.question1; //case 1
_root.test = this["question"+a]; //case 2
_root.test1 = eval("this.question" add a); //case 3
}

in case 1, _root.test2 displays value. the value is right.
and the value should be 1+1=?, but it dislays 1 1=?...dont know why.....how can it appears +?

in case 2 and 3, they have no any value.. just empty..
sth missing to code? thanks....

thanks for help
 
i have solved.
but i can't solve one thing
in db, the value is 1+1=?
but the browser display 1 1=?
it omit "+".

any suggestion to solve?!

thanks
 
'+' is a reserved character you can get around this by replacing it with %2B in the database which will be escaped to '+' in your Flash movie.
 
question = new LoadVars();
question.onLoad = function(success) {
if (success) {
for (a=1; a<=this.total; a++) {
_global.z=this.total;
var dataObj = new Object();
dataObj.question = eval("this.question"+a);
dataObj.answer1 = eval("this.answer1"+a);
dataObj.answer2 = eval("this.answer2"+a);
dataObj.answer3 = eval("this.answer3"+a);
_root.arrayQuestion[a] = dataObj;
}
} else {
_root.test3 = "not success";
}
};
question.load("game1.php");
_root.test3=_global.z ;

whatever i code _global.z or _root.z in for loop, _root.test3 is empty. any method to do that _root.test3 has a value ?!
thanks
 
First thing is that you shouldn't decalre globals in the way you have in your example - define it once then refer to it by variable name alone:

Code:
_global.val;
//but afterwards just
val=3;//etc.

If you keep using _global in front of the variable name you're actually creating a new global variable every time instead of updating one variable.

Second thing is you're trying to set _root.test3 too soon - the data needs time to do the round trip to the server first. Try setting
Code:
_root.test3=_global.z

inside of the onLoad event and you'll get a result.
 
I should have written

Code:
_root.test3=z

In the above example instead of copying and pasting...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top