PDA

View Full Version : Losing Variables between Flash and PHP (sortof)


aeohn
06-08-2005, 02:50 AM
Ok, the idea is to drag a LARGE number of objects (95) to various locations then save their locations to a serverside .txt using SendAndLoad as well as a PHP file.

Out of 95 variables about 75 of them work correctly and the rest (all accessed in a row) end up with zero as their value. The code is as follows for send from Flash:


function savephrase(){
savers = new LoadVars();

savers.alllocs = "a1x="+Math.Round(a1._x)+"&a1y="+Math.Round(a1._y)+"&a2x="+Math.Round(a2._x)+"&a2y="+Math.Round(a2._y)+"&a3x="+Math.Round(a3._x)+"&a3y="+Math.Round(a3._y)+"&a4x="+Math.Round(a4._x)+"&a4y="+Math.Round(a4._y)+"&a5x="+Math.Round(a5._x)+"&a5y="+Math.Round(a5._y)+"&b1x="+Math.Round(b1._x)+"&b1y="+Math.Round(b1._y)+"&b2x="+Math.Round(b2._x)+"&b2y="+Math.Round(b2._y)+"&b3x="+Math.Round(b3._x)+"&b3y="+Math.Round(b3._y)+"&c1x="+Math.Round(c1._x)+"&c1y="+Math.Round(c1._y)+"&c2x="+Math.Round(c2._x)+"&c2y="+Math.Round(c2._y)+"&c3x="+Math.Round(c3._x)+"&c3y="+Math.Round(c3._y)+"&d1x="+Math.Round(d1._x)+"&d1y="+Math.Round(d1._y)+"&d2x="+Math.Round(d2._x)+"&d2y="+Math.Round(d2._y)+"&d3x="+Math.Round(d3._x)+"&d3y="+Math.Round(d3._y)+"&d4x="+Math.Round(d4._x)+"&d4y="+Math.Round(d4._y)+"e1x="+Math.Round(e1._x)+"&e1y="+Math.Round(e1._y)+"&e2x="+Math.Round(e2._x)+"&e2y="+Math.Round(e2._y)+"&e3x="+Math.Round(e3._x)+"&e3y="+Math.Round(e3._y)+"&e4x="+Math.Round(e4._x)+"&e4y="+Math.Round(e4._y)+"&e5x="+Math.Round(e5._x)+"&e5y="+Math.Round(e5._y)+"&e6x="+Math.Round(e6._x)+"&e6y="+Math.Round(e6._y)+"&e7x="+Math.Round(e7._x)+"&e7y="+Math.Round(e7._y)+"&e8x="+Math.Round(e8._x)+"&e8y="+Math.Round(e8._y)+"&f1x="+Math.Round(f1._x)+"&f1y="+Math.Round(f1._y)+"&f2x="+Math.Round(f2._x)+"&f2y="+Math.Round(f2._y)+"&g1x="+Math.Round(g1._x)+"&g1y="+Math.Round(g1._y)+"&g2x="+Math.Round(g2._x)+"&g2y="+Math.Round(g2._y)+"&g3x="+Math.Round(g3._x)+"&g3y="+Math.Round(g3._y)+"&h1x="+Math.Round(h1._x)+"&h1y="+Math.Round(h1._y)+"&h2x="+Math.Round(h2._x)+"&h2y="+Math.Round(h2._y);

savers.filename = "data/fridge/"+user+".txt";

savers.alllocs2 = "h3x="+Math.Round(h3._x)+"&h3y="+Math.Round(h3._y)+"&i1x="+Math.Round(i1._x)+"&i1y="+Math.Round(i1._y)+"&i2x="+Math.Round(i2._x)+"&i2y="+Math.Round(i2._y)+"&i3x="+Math.Round(i3._x)+"&i3y="+Math.Round(i3._y)+"&i4x="+Math.Round(i4._x)+"&i4y="+Math.Round(i4._y)+"&i5x="+Math.Round(i5._x)+"&i5y="+Math.Round(i5._y)+"&j1x="+Math.Round(j1._x)+"&j1y="+Math.Round(j1._y)+"&k1x="+Math.Round(k1._x)+"&k1y="+Math.Round(k1._y)+"&k2x="+Math.Round(k2._x)+"&k2y="+Math.Round(k2._y)+"&l1x="+Math.Round(l1._x)+"&l1y="+Math.Round(l1._y)+"&l2x="+Math.Round(l2._x)+"&l2y="+Math.Round(l2._y)+"&l3x="+Math.Round(l3._x)+"&l3y="+Math.Round(l3._y)+"&l4x="+Math.Round(l4._x)+"&l4y="+Math.Round(l4._y)+"&m1x="+Math.Round(m1._x)+"&m1y="+Math.Round(m1._y)+"&m2x="+Math.Round(m2._x)+"&m2y="+Math.Round(m2._y)+"&n1x="+Math.Round(n1._x)+"&n1y="+Math.Round(n1._y)+"&n2x="+Math.Round(n2._x)+"&n2y="+Math.Round(n2._y)+"&n3x="+Math.Round(n3._x)+"&n3y="+Math.Round(n3._y)+"&n4x="+Math.Round(n4._x)+"&n4y="+Math.Round(n4._y)+"&n5x="+Math.Round(n5._x)+"&n5y="+Math.Round(n5._y)+"&n6x="+Math.Round(n6._x)+"&n6y="+Math.Round(n6._y)+"&n7x="+Math.Round(n7._x)+"&n7y="+Math.Round(n7._y)+"&o1x="+Math.Round(o1._x)+"&o1y="+Math.Round(o1._y)+"&o2x="+Math.Round(o2._x)+"&o2y="+Math.Round(o2._y)+"&o3x="+Math.Round(o3._x)+"&o3y="+Math.Round(o3._y)+"&o4x="+Math.Round(o4._x)+"&o4y="+Math.Round(o4._y)+"&o5x="+Math.Round(o5._x)+"&o5y="+Math.Round(o5._y)+"&p1x="+Math.Round(p1._x)+"&p1y="+Math.Round(p1._y);

savers.filename2 = "data/fridge/"+user+"2.txt";

savers.alllocs3 = "p2x="+Math.Round(p2._x)+"&p2y="+Math.Round(p2._y)+"&q1x="+Math.Round(q1._x)+"&q1y="+Math.Round(q1._y)+"&r1x="+Math.Round(r1._x)+"&r1y="+Math.Round(r1._y)+"&r2x="+Math.Round(r2._x)+"&r2y="+Math.Round(r2._y)+"&r3x="+Math.Round(r3._x)+"&r3y="+Math.Round(r3._y)+"&r4x="+Math.Round(r4._x)+"&r4y="+Math.Round(r4._y)+"&r5x="+Math.Round(r5._x)+"&r5y="+Math.Round(r5._y)+"&s1x="+Math.Round(s1._x)+"&s1y="+Math.Round(s1._y)+"&s2x="+Math.Round(s2._x)+"&s2y="+Math.Round(s2._y)+"&s3x="+Math.Round(s3._x)+"&s3y="+Math.Round(s3._y)+"&s4x="+Math.Round(s4._x)+"&s4y="+Math.Round(s4._y)+"&t1x="+Math.Round(t1._x)+"&t1y="+Math.Round(t1._y)+"&t2x="+Math.Round(t2._x)+"&t2y="+Math.Round(t2._y)+"&t3x="+Math.Round(t3._x)+"&t3y="+Math.Round(t3._y)+"&t4x="+Math.Round(t4._x)+"&t4y="+Math.Round(t4._y)+"&t5x="+Math.Round(t5._x)+"&t5y="+Math.Round(t5._y)+"&u1x="+Math.Round(u1._x)+"&u1y="+Math.Round(u1._y)+"&u2x="+Math.Round(u2._x)+"&u2y="+Math.Round(u2._y)+"&u3x="+Math.Round(u3._x)+"&u3y="+Math.Round(u3._y)+"&v1x="+Math.Round(v1._x)+"&v1y="+Math.Round(v1._y)+"&v3x="+Math.Round(v3._x)+"&v3y="+Math.Round(v3._y)+"&w1x="+Math.Round(w1._x)+"&w1y="+Math.Round(w1._y)+"&w2x="+Math.Round(w2._x)+"&w2y="+Math.Round(w2._y)+"&w3x="+Math.Round(w3._x)+"&w3y="+Math.Round(w3._y)+"&x1x="+Math.Round(x1._x)+"&x1y="+Math.Round(x1._y)+"&x2x="+Math.Round(x2._x)+"&x2y="+Math.Round(x2._y)+"&y1x="+Math.Round(y1._x)+"&y1y="+Math.Round(y1._y)+"&y2x="+Math.Round(y2._x)+"&y2y="+Math.Round(y2._y)+"&z1x="+Math.Round(z1._x)+"&z1y="+Math.Round(z1._y)+"&z2x="+Math.Round(z2._x)+"&z2y="+Math.Round(z2._y);

savers.filename3 = "data/fridge/"+user+"3.txt";

savers.SendAndLoad("http://www.webgavel.com/savemagsa.php?"+Math.Round(Math.Random()*2000), savers, "POST");

while(!savers.OnLoad){}
delete savers;
}


and savemagsa.php is as follows:


<?
$content = $_POST["alllocs"];
$filename = $_POST["filename"];
$fp=fopen($filename,"w");
fwrite($fp,$content);
fclose($fp);
$content = $_POST["alllocs2"];
$filename = $_POST["filename2"];
$fp=fopen($filename,"w");
fwrite($fp,$content);
fclose($fp);
$content = $_POST["alllocs3"];
$filename = $_POST["filename3"];
$fp=fopen($filename,"w");
fwrite($fp,$content);
fclose($fp);
?>


Now I've gone about this quite a few different ways... I was sending ALL the values to the PHP and compiling the huge string there to be sent to the txt file. That wasn't working very well at all so I changed it to this way (compile the huge strings in Flash then send them as 1 variable per file)

Basically, what the problem is is towards the end of the 3rd file about 15 variables are set to 0... and those 15 are towards the middle the last file... variables are changed correctly before and after them.

Now I can understand how hard it may be to fish through my code... but I think the problem is related to memory use within Flash.

Is there a better alternative to LoadVars() or SendandLoad()? Thanks!

beanSoldier
06-23-2005, 11:08 AM
your problem is the number of variables you have there. 95!

if you need all those variables attach them to the loadVars() saver object with a script. don't write all that out yourself.

stick all those values in an array or xml file and loop through them and assign them to the saver loadVars variable.