TwelvestoneFlash

Help with LoadVars() 'sendAndLoad' method


Sign in

  • Waiting for Godot ( 730 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 5.1 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.9 k posts )
    general front end design an...
  • Back End ( 9.7 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
faerieprince
 
2003-01-28

Okay,

I am not sure why this is happening, but here is the case. I am trying to stay current with the new features of MX, and this one is confusing me. I understand the gist of the 'new LoadVars ();' object. I can get the '.send' and '.load' to work. I can even use the '.load' with the '.onLoad'. But somehow, I cannot get the '.sendAndLoad' to work! I set a loop in my movie to wait for the result to come back. Flash understands that something has come back because it exits my loop. I am, however, unable to recover what is sent to my movie!

I can only think that it is my .php. I realize this is not the forum for .php, but since this is primarily a Flash question I think this is the best forum.

Persist is using this in his 'weather' experimental app (which is fabulous), so hopefully he will come across this and have some advice.

I am posting my code for you to see. Any help would be appreciated k

****** PHP CODE ******

<?php

$name = $_POST['vname']; $email = $_POST['vemail']; $message = $_POST['vmessage']; $favAnimal = $_POST['AID']; $mailList = $_POST['mlist'];

// open connection to database $connection = mysql_connect("localhost", "***", "***") or print "&display=" . urlencode("Unable to connect!"); mysql_select_db("form") or print "&display=" . urlencode("Unable to select database!");

// formulate and execute query $query = "INSERT INTO visitor (name, email, message, favAnimal, mailList) VALUES ('$name', '$email', '$message', '$favAnimal', '$mailList')"; $result = mysql_query($query) or die ("Error in query: " . mysql_error());

$msg = "&champion=" . urlencode ("We did it!");

echo ($msg);

// clean up mysql_close($connection);

?>

****** SCRIPT IN FRAME 1 ********

function showResult (success) { if (success) { gotoAndStop (5); trace ("record added"); } }

function processForm (btn) { if (btn._name == "clear") { visitorName = ""; visitorEmail = ""; visitorMessage = ""; animal.setSelectedIndex (0); mailList.setValue (false); } else if (btn._name == "submit") { formData = new LoadVars (); formData.vname = visitorName; formData.vemail = visitorEmail; formData.vmessage = visitorMessage; formData.AID = animal.getSelectedItem().data; if (mailList.getValue()) { formData.mlist = 1; } else { formData.mlist = 0; } formData.action = "add"; formData.sendAndLoad (dataURL+"guestbook.php", formData); formData.onLoad = showResult; } }

dataURL = "form/";

Again, I am writing to the database, and I can retrieve something from it. It is just not displaying. Any thoughts? I could provide the .fla if anyone is interested/ thinks it might help them.

the real me
 
2003-01-28

so you are getting the data back into flash then? it's just not displaying somewhere, is that what you mean?

faerieprince
 
2003-01-28

Yes, I think. I have the .onLoad call a function that checks if the data transfer was a success. I have messed with the file name of the .php just to make sure it was not always firing. The function does seem to only work with a proper file call, so I assume the data is coming into my movie.

What I am unable to do is use the information returned. If I just do a '.load' it works just fine. There seems to be something I am missing with the '.sendAndLoad' method.

Sort of frustrating.

the real me
 
2003-01-28

well i'm actually not sure if it's required, i don't think it is, but i normally define a seperate object to recieve the data for the load. try that maybe?

faerieprince
 
2003-01-28

Is this what you mean:

    returnData = new LoadVars ();
    formData.sendAndLoad (dataURL+"guestbook.php", returnData);
    returnData.onLoad = showResult;

I appended this to the bottom of the script I posted in the start of this thread. It still does not seem to work! Is the problem that it all exists in the same function? Should I create my LoadVars outside of this function? Perhaps scope has something to do with it?

Thanks for your help. Any further ideas? Would it help to see my .fla?

the real me
 
2003-01-29

yeah that's what i meant. but still not working huh? it shouldn't cause a problem with your onload being in the same function but what if you try it like this maybe.

formData.onLoad = function(success) { if (success) { gotoAndStop (5); trace ("record added"); } }

or maybe one of the ultra flash guru experts will come along and be able to spot your problem if that doesn't work k

faerieprince
 
2003-01-29

I will give that a shot. In the meantime, I think I might PM persist and direct him to this thread for assistance.

Thanks for your thoughts, feel free to post any others you have k

persist
 
2003-01-29

Hmm, here's a test php: [php] <?

$input = "&champion= $News +". urlencode ("We did it!");
echo $input;

?> [/php]

Here's the test AS:

formData = new LoadVars(); formData.News = "test"; returnData = new LoadVars(); formData.sendAndLoad ("http://www.pixelplay.org/jeff/php/formtest.php", returnData); returnData.onLoad = showresult; function showresult(success){ trace(success); trace(unescape(returnData)); }

and all is working fine.

Is your php returning errors for an sql failure?

faerieprince
 
2003-01-29

I get the trace (success) to come in as 'true', but there is no other traced message. I even tried changing this to just a .load and (now) it seems that it does not even work properly :confused:

Another strange thing, I added a 'gotoAndStop (3);' into the onLoad. I thought that if it was tracking that something was returned, this would be another visual check since I am not able to get any display. I still get true, but it does not go to frame 3!

I am not able to display anything coming from my .php. I am not getting a server error of any kind.

WARGG!

Any thoughts?

persist
 
2003-01-29

honestly I;d open a new empty fla and try tesitng in there. something bizarre is going on if that's the case. you need to at least verfiy the loadvars object is receiving the data, and then you can move onto why your movie isn't responding to anyhting in the onload.

faerieprince
 
2003-01-29

Not to sound like too much of a wimp, but would you please just create a source file for me? I just think that I might be missing some crucial step. It does not have to do anything beyond what the code does, but maybe I am just screwing it up along the way :(

If you have time, I would greatly appreciate it. I have it working with flash 5 syntax, but not with MX. I would like to stay on the frontline of this technology if possible.

Thanks in advance!

persist
 
2003-01-30

I guess I don't understand what your asking me to make an fla of.

I don't have an sql server so I can't check to see ifyourcode is actually writing to your database.

Your send and load method works as in the example I posted, which would take about .24 seconds to make an fla and a php file by copy pasting.

It's no trouble at all, but an fla like that shouldn't take long to transfer the code from your existing movie and run the functions on their own, and watch what it traces.

??

persist
 
2003-01-30

to be honest I think sendandload is kind of silly. it seems like an attmept to compact code, but having to simply make two objects to do the job of one merely helps you compartmentalize your vars when using post, so you don't end up sending a whole wagon of crap the php doesn't need.

other than that I hate using "post" to append my vars, usually because I like to watch the length of them and call a url multiple times if the length gets ridiculous. i like to append data onto the server from a client machine rather than one boggy url chunk. HOW LUCKY FOR US WE CAN DO THIS WITH FLASH. So I prefer to append uRL's by constructing the string in flash myself. but I am a dork, and still stuck in Flash 5 land sometimes.

For example look how much more control I have over the url's vars in this common save/append/read/delete java socket call:

callXMLsock("SaveFile", "fileName=userLog.txt&append=true"+"&fileContent="+escape(content));

function callXMLsock(method, string) { foobar = new XML(); foobar.ignoreWhite = true; foobar.load('http://127.0.0.1:2000/'+method+'?'+string); foobar.onLoad = function(success) { content = (foobar.childNodes[0].nodeValue); if (substring(content, 0, 4) == 'r200') { message = "The string successfully appended to the server."; content = ""; } else if (substring(content, 0, 4) == 'r500') { message = "File not found."; content = ""; } }; }

subman
 
2003-01-30

have a look on shockwave.com, they had a thing about loadvaribles that's not working propaly. You can embed some varibales in the html like flashvars or something...

Hope this helps..

I had this problem with php and flash not reading the variables..

faerieprince
 
2003-01-30

persit: I realize that copy and paste would take a fraction of seconds. I tried that and it was not working. Even the traces were not all firing. So I thought that maybe I was not allowing enough time for the data to be returned or maybe because there was only one frame that Flash was not able to update itself. I thought that maybe there needed to be extra frames/internal loop/whatever that I was just not including. I guess that is not the case.

Does this .onLoad command need to be set with a loop or is it just smart enough to constantly check (or wait) until the data arrives before carring out the code?

I think your assesment of sendAndLoad might be right. If it works as two different calls, I should probably just keep it as such.

Regarding your appending a URL approach, that is pretty clever. I thought you were limited to the length of a request sent this way. Normally this would not be a problem. But if I were updating or creating a story for my site I thought it would not accept all the information because it is too long. Have you experienced a cap on the length of the URL string?

Subman: I will check that out. It makes me feel a little better hearing that others are having issues with this. It seems so simple to do that I have been going batty trying to figure out why it is not working. Perhaps some answers are on Shockwave.com

Thank you both very much for your assistance and time!

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneFlash

Help with LoadVars() 'sendAndLoad' method