PDA

View Full Version : Help please! send() works - sendAndLoad() doesn't!


Das123
04-07-2004, 09:37 PM
Hi all,
I'm developing a Flash application that has data fed into it through php from a mySQL database. The user can then do some editing within the Flash file and the revised data is then sent back to the database through another php script.
I can get the data into the arrays using loadVars().load without too much problem.
And I can send the data back out using loadVars().send which opens up a new file.

My issue is that I want the data transfer to be invisible, so I need to use the sendAndLoad() method.

Here is the current script attached to the submit button:

on (click) {
changes = new LoadVars();
changes.id = _parent.id;
changes.title = _parent.title.text;
changes.groupID = _parent.groupCombo.selectedItem.data;
changes.phone = _parent.phone.text;
changes.area = _parent.area.text;
changes.detail = _parent.detail.text;

changes.onLoad = function(success){
if(success){
_parent.detail.text="Worked";
} else {
_parent.detail.text="Problems";
}
}
changes.sendAndLoad("sendRegion.php?uniqueID="+getTimer(), changes, "POST");
//This works...
//changes.send("sendRegion.php?uniqueID="+getTimer(), "_blank", "POST");
}


If I test the script directly through Flash (without using the server) I get the error message:
"Error opening URL "file:///... etc .../sendRegion.php?uniqueID=3017"
Even if I point to an empty html file rather than a PHP file I still get this error message.
The 'detail' text box has the flag "Problems".

My PHP file simply reads the $_POST[] array but doesn't output anything other than an "id=test' for testing purposes.

$id = $_POST['id'];
$title = $_POST['title'];
$groupID = $_POST['groupID'];
$phone = $_POST['phone'];
$area = $_POST['area'];
$detail = $_POST['detail'];

Print "id=test"


If I publish files and run them through the server, nothing at all happens when I click the submit button except that the php file can no longer be edited as it is in use. I can continue to use the shockwave file.

CyanBlue
04-07-2004, 10:36 PM
Howdy and Welcome... :)

That's really strange... Hm... I just copied and pasted your scirpt and tested what you had on my FMX/IIS and it worked perfectly with sendAndLoad() function... What's your Flash version and the version of the Flash Player???

Das123
04-07-2004, 11:13 PM
Thanks CyanBlue,

I'm using FlashMX2004, FlashPlayer 7, Testing on Win2000 running IIS.
It's heartening to hear it's working for you. I might set up a small test file to see if I can get it to work that way, then slowly introduce it to my main file.
I'll post the results.

BTW, thanks for your excellent posts throughout the forum. They have saved me hours upon hours of coding. :)

CyanBlue
04-07-2004, 11:19 PM
Run the file that I have attached to see if it works for you or not... I think you can set the http://path correctly to get it working within the Flash itself...

Check to see if the PHP file generates any error when you call it from the web browser as well... I doubt that there is any error in your PHP file since it works with send() function but you might want to double check on that...

And, thanks for the compliment... and glad to hear that it helped you abit... :)

Das123
04-08-2004, 02:49 AM
Your file works fine, even without the absolute address.

The only difference I can see is the button object. I had used one of the Flash UI Component buttons and it liked the 'on(click)'. By placing a button clip and using 'on (press)' or 'on (release)' the file works. I don't know why. There must be something about the component button that interferes.

Thanks again for your help. :)

CyanBlue
04-08-2004, 06:14 AM
Huh... That's really funky... :D

I have not had much experiences with FMX 2004, but it sounds very funky to me... My suggestion... Downgrade back to FMX... Hehe... Just kidding... But I guess that's where I have to stop... I just didn't have used 2004 much... But keep me posted on what you find out... :)

freddycodes
04-08-2004, 01:15 PM
$id = $_POST['id'];
$title = $_POST['title'];
$groupID = $_POST['groupID'];
$phone = $_POST['phone'];
$area = $_POST['area'];
$detail = $_POST['detail'];

Print "id=test"


If that is the exact contents of your php script, I would say you have syntax errors.
Missing semi-colon on the Print line.

Das123
04-08-2004, 03:43 PM
If that is the exact contents of your php script, I would say you have syntax errors.
Missing semi-colon on the Print line.
It isn't good code, but there is no syntax error because its the last line of the php.

freddycodes
04-08-2004, 04:16 PM
What is that supposed to mean? A missing semi-colon will throw a php error whether its on the first line or the last line.

Das123
04-08-2004, 10:46 PM
print and echo don't require a semi-colon if they are the last command within php tags. These examples will print...

<?php print "a line of text<br>" ?>
<?php print "another line...<br>" ?>


This wont work because the first line needs a semi-colon...
<?php
print "Multiple lines within tags<br>"
print "another line..."
?>

I agree with you that semi-colons should be placed as good coding practice, though. :)

freddycodes
04-09-2004, 12:34 AM
You seem to be correct, considering my expertise in the area of php although I haven't worked with in several years, I did not know that. However its another point to me made about how loose php is.

Das123
04-12-2004, 11:11 PM
Here's the wrap-up...

The code did work ... eventually.

In my flash file, I have a lot of animation and calculations going on that are controlled with on (enterFrame) events as it loops through the file. The test files worked almost instantly and I was assuming that the problem must be with the UI Components I had used. When I brought the test files across into my movie, they also wouldn't work. I finally realised that the sendAndLoad was firing, but only after about two minutes! When I deleted the objects that were animating in the background, the file worked fine.

Now I just need to work out how to get the file to load AND allow the rest of my animations elements to work as well. Hmmmm any ideas? :confused:

PS. The file also wanted to have absolute references within the load function. Instead of _parent.object.text I needed to use _root.instanceName.object.text

Thanks again for your help.

CyanBlue
04-13-2004, 10:54 AM
As for your first question, I can't really say because it is something that I don't see in front of my eyes, but I don't see why you can't have loading the text file and running the animation at the same time...

As for the second question... Once you are within the LoadVars()'s onLoad handler, 'this' refers the LoadVars() object itself rather than pointing the timeline... Did that answer your question???

Das123
04-14-2004, 03:57 PM
Thanks. I wasn't aware about the referencing within the onLoad handler. That makes sense.

The project is a shopping centre map with a translucent directory down one side, and a zooming and scrolling map in the centre. The details of the shops are inside the database and each shop is also part of a group, eg. gifts, homewares etc., wich is also a table in the database. The group colour codes the shops and also colour codes the directory.

As far as the animations are concerned, I had zooming and scrolling happening where the distance the map travelled was always a fraction between the current position and the target position, so in theory it never actually arives at its destination. The directory consists of instances of a button that are personalised with content and colour.

My sendAndLoad script was for my client to be able to alter the details of the individual shops. They would click on a shop, then make the changes, then submit the changes. With the map and directory on the screen, the submission was taking around 120 seconds. If I hid the directory, the submission fell to about 10 seconds. And if I also hid the 'all-scrolling-all-zooming' map, the submission process only took a split second.

To work around this, I just put my edit form on a new frame, then moved back to the map after the form was submitted.