PDA

View Full Version : sendAndLoad not happening for newbie


snazzyslippers
02-15-2005, 05:36 PM
Hi, I'm a newb.

I recently got a script to send() a post to php.

I modified it to return variables to Flash for output using sendAndLoad(). The modifications were very basic, but it doesn't work. Nothing happens at all. Can someone take a look at it for me?

Here is my script:

function showContent()
{
output_text.text = "";
output_text.text += this["fileName"];
}

var dataSender = new LoadVars();
dataSender.onLoad = showContent;

butinst.onRelease = function()
{
dataSender.file = _parent.input_text.text;
dataSender.sendAndLoad("dynamicout.php","dataSender","POST");

}

here is my php:

<?php

$file = $_POST['file'];
echo "fileName=".$file;

?>

deadbeat
02-15-2005, 05:41 PM
Try taking the target object out of the quotes:

dataSender.sendAndLoad("dynamicout.php",dataSender,"POST");

K.

snazzyslippers
02-15-2005, 05:50 PM
Thank you!

I get output now, but it says 'undefined'.

deadbeat
02-15-2005, 05:59 PM
Try adding a trace to your button onRelease, to see if the text field value is being picked up correctly - you may need to path it differently:

butinst.onRelease = function()
{
trace("Text: "+_parent.input_text.text);
dataSender.file = _parent.input_text.text;
dataSender.sendAndLoad("dynamicout.php","dataSender","POST");
}


K.

snazzyslippers
02-15-2005, 08:12 PM
That's it, it didn't trace it. So how do I figure out what the correct path is?

Thanks

deadbeat
02-15-2005, 08:22 PM
Well, is your butInst a Button or a MovieClip that acts as a button? And where is your input_text field relative to that?

K.

snazzyslippers
02-15-2005, 08:31 PM
It is a movieclip that acts like a button, and they are both on _level0. However, I have tried that path with and without _parent and I get the same result.

Thanks for your patience!

deadbeat
02-15-2005, 08:32 PM
Does input_text have an instance name?

snazzyslippers
02-15-2005, 08:40 PM
input_text is the instance name of that field.

deadbeat
02-15-2005, 08:41 PM
Then _root.input_text.text or _level0.input_text.text should do it...

If you still can't figure out the path, try looking in the Movie Explorer panel, or in the Debugger to find the right path...

K.

snazzyslippers
02-15-2005, 08:59 PM
The debugger says that it is _level0.input_text. I tried it! And _root! Gah!!

snazzyslippers
02-15-2005, 11:31 PM
I'm sorry. I just realized what was happening with the debugger.

the _level0.input_text worked, it traced the input. There is just no output. It can't be the php. Is there maybe a problem with the output function?

Thank you

UncleML
02-15-2005, 11:49 PM
I'm sorry to interrupt. Just that I noticed you're using sendAndLoad, you need two variables, one for the input, and the other for the output. Why don't you do all together when the button is pressed, and not pre-do it before the button is pressed?

snazzyslippers
02-16-2005, 12:06 AM
Thanks, I just tried that, and it produces the same result. I have the whole thing simplified to:

butinst.onRelease = function()
{

var dataSender = new LoadVars();
dataSender.file = _level0.input_text.text;
dataSender.sendAndLoad("dynamicout.php",dataSender,"POST");
dataSender.onLoad = showContent;

}

function showContent()
{
_level0.output_text.text = this["fileName"];
}

Is there a way to put a path on this["filename"]?

carlos_queiroz
02-16-2005, 12:20 AM
hi
theres a problem in your script
you cant receve on the same var you send
try this wait
hope it'll help

var LV=new LoadVars();//load
var SV=new LoadVars();//send
LV.onLoad=function(){
DoSomething();
}
SV.sendAndLoad("file.php",LV,"post");

UncleML
02-16-2005, 12:27 AM
As I said already, since you're using sendAndLoad, you need two variables, one for the input (incoming), and the other for the output (outgoing). Why you need to call the function showContent()?


butinst.onRelease = function()
{
var dataSender:LoadVars = new LoadVars();
var status_lv:LoadVars = new LoadVars();
status_lv.onLoad = function(prm_status:Boolean) {
if (prm_status) {
trace("successful);
trace("status_lv replay is "+status_lv);
} else {
trace("connecting failed");
}
};
dataSender.file = _level0.input_text.text;
dataSender.sendAndLoad("dynamicout.php",status_lv,"POST");
}

function showContent()
{
_level0.output_text.text = this["fileName"];
}

snazzyslippers
02-16-2005, 12:40 AM
Thanks,

I just tried:

butinst.onRelease = function()
{
var SV = new LoadVars();
var LV = new LoadVars();
SV.file = _level0.input_text.text;
SV.sendAndLoad("dynamicout.php",LV,"POST");
LV.onLoad = showContent;

}

function showContent()
{
_level0.output_text.text = this["fileName"];
}

and it still returns 'undefined'.

snazzyslippers
02-16-2005, 12:43 AM
Oh, I just saw your message uncleML, thanks! I'll try it.

snazzyslippers
02-16-2005, 12:55 AM
successful
status_lv replay is %0D%0A%3C%3Fphp%0D%0A%0D%0A%24file%20=%20%24%5FPOS T%5B%27file%27%5D%3B%0D%0Aecho%20%22fileName%3D%22 %2E%24file%3B%0D%0A%0D%0A%3F%3E%0D%0A&onLoad=%5Btype%20Function%5D


but what does it mean??

snazzyslippers
02-16-2005, 01:02 AM
Actually, I don't need to call the function for this, I just have it set up that way because eventually, HOPEFULLY there will be a bunch more stuff that happens on onLoad.

UncleML
02-16-2005, 01:10 AM
Since the status is Ok, that means it already successfully connecting.
If you unescape it, you'll get the result as below. Maybe you can tell me what you intend to do with this and you've to check whether the php content is correct as I don't know php. If you want to get the reply upon sending, for a specific php variable, say here "filename", you may apply the below right after the "status_lv.reply"

trace("status_lv replay is "+status_lv);
trace("filename is "+status_lv.filename);

check also for the content in your text field by using trace within the button.onRelease function.

trace("_level0.input_text.text");


<?php
$file = $_POST['file'];
echo "fileName=" .$file;
?>

snazzyslippers
02-16-2005, 01:35 AM
Okay, now I get

successful
status_lv replay is %0D%0A%3C%3Fphp%0D%0A%0D%0A%24file%20=%20%24%5FPOS T%5B%27file%27%5D%3B%0D%0Aecho%20%22fileName%3D%22 %2E%24file%3B%0D%0A%0D%0A%3F%3E%0D%0A&onLoad=%5Btype%20Function%5D
filename is undefined


I put the trace for the output in the ShowContent function also -- nothing came back for that.

CyanBlue
02-16-2005, 01:39 AM
That probably means that your host does not support the PHP or you are not calling the PHP file correctly...

Open up the IE and run that PHP file by typing the http://blahblah/some.php and tell us what you see...

PS> Please use AS/PHP tag to format the code...

UncleML
02-16-2005, 01:47 AM
Why you need to trace ShowContent, the program is not going to call it if you follow closely the code I gave you? You can dump ShowContent anyway.

You get the "The filename is undefined" because the variable "filename" not valid in your php file. I guess it is supposed to be "file" not "filename". Anyway, I'm trying to tell you the connection is successful at Flash end. Now, it is done fine with Flash. You have to check at the other end. The problem now is no more in Flash. So, I can't help you out with the PHP file and at the other end.

Should you want to see all variables in your sending php file, you can insert the below after the trace:


butinst.onRelease = function()
{
var dataSender:LoadVars = new LoadVars();
var status_lv:LoadVars = new LoadVars();
status_lv.onLoad = function(prm_status:Boolean) {
if (prm_status) {
trace("successful);
//trace("status_lv replay is "+status_lv);
for (var prop in status_lv) {
trace(prop+" -> "+status_lv[prop]);
}

} else {
trace("connecting failed");
}
};
dataSender.file = _level0.input_text.text;
dataSender.sendAndLoad("dynamicout.php",status_lv,"POST");
}

UncleML
02-16-2005, 01:48 AM
CyanBlue is absolutely correct. I hands off now. Thanks.

CyanBlue
02-16-2005, 01:54 AM
Uh... Uh... I was about to go to sleep... :o :eek:

snazzyslippers
02-16-2005, 01:56 AM
Apparently the php is good -- when I call the script on my server I get the output string!

It says

fileName = Hi

(Hi is what I input).

The file, called dynamicout.php, contains:

<?php

$file = $_POST['file'];
echo "fileName=".$file;

?>

UncleML
02-16-2005, 02:18 AM
Hahaha CyanBlue, you can't run away coz I got to get off now for my trip. Anyway, SnazzySlippers, the flash is working fine now. It's at your the other end needs to receive and at the same time, send whatever required information back to flash.

snazzyslippers
02-16-2005, 02:22 AM
I just tried that last code that uncleML gave me, and I get:

?>


onLoad -> [type Function]
successful


<?php

but I want the result to show up in my output text field. That was what ShowContent was supposed to to.

Forgive me for being such a newb.

CyanBlue
02-16-2005, 02:28 AM
Have a nice and safe trip, UncleML... :)

Are you testing it over the web browser or within the Flash itself???

The ideal way of testing it would be to publish the HTML file from the publish menu and run that over the web browser by using the http protocol... If not, you could provide the full path including the http when you call that dynamicout.php file...

Once that's done, you could add that output part within the onLoad handler like this...

status_lv.onLoad = function(prm_status:Boolean) {
if (prm_status) {
trace("successful");
...
outputTextFieldInstanceName.text = this.fileName;
...
} else {
trace("connecting failed");
}
};

snazzyslippers
02-16-2005, 02:44 AM
I'm testing in Flash and also uploading to the server and testing there.

When I test in Flash now with the output code in there I get:

successful


<?php



$file -> $_POST['file'];

echo "fileName=".$file;



?>


onLoad -> [type Function]
successful


<?php


BUT when I upload it and test it, I still get 'undefined' in the output field! You can see that it is definitely posting to php and php is returning, but something is happening to the output.

Here is the exact code that produces that result:


butinst.onRelease = function()
{
var dataSender:LoadVars = new LoadVars();
var status_lv:LoadVars = new LoadVars();
status_lv.onLoad = function(prm_status:Boolean) {
if (prm_status) {
trace("successful");
output_text.text = this.fileName;
//trace("status_lv replay is "+status_lv);
for (var prop in status_lv) {
trace(prop+" -> "+status_lv[prop]);
}

} else {
trace("connecting failed");
}
};
dataSender.file = _level0.input_text.text;
dataSender.sendAndLoad("dynamicout.php",status_lv,"POST");
}

snazzyslippers
02-16-2005, 03:05 AM
A new development!

I entered the full url for the php as you suggested in sendAndLoad.

Now when I test it in Flash (typing 'hi' into the input field), I get

successful


fileName -> hi
onLoad -> [type Function]



But the output field still reads 'undefined'.

CyanBlue
02-16-2005, 03:08 AM
I believe that you are saying that you are actually seeing this in the output panel, correct???
successful


<?php



$file -> $_POST['file'];

echo "fileName=".$file;



?>


onLoad -> [type Function]
successful


<?php
That means that Flash is loading the PHP file as if it is a text file... That's why you are seeing the tags like <? or ?>... That's why you have to run it over the http protocol...

At any rate... Here is the sample file that works on my computer and on my host... See if you can find the difference... ;)
http://cyanblue.flashvacuum.com/tmp/snazzyslippers/dynamicout.html
http://www.flashvacuum.com/~cyanblue/tmp/snazzyslippers/dynamicout.html

snazzyslippers
02-16-2005, 03:18 AM
Ha ha, nice button!

Can I see your actionscript code?

Thanks so much,
L

snazzyslippers
02-16-2005, 03:23 AM
Can you make the output field just say 'text'?

snazzyslippers
02-16-2005, 03:49 AM
The difference in output is that in my output display (which does not display in my output_text field),

fileName -> test
onLoad -> [type Function]


Your output field displays

fileName -> test
onLoad -> [type Function]
test

CyanBlue
02-16-2005, 10:09 AM
What you are saying does not make sense to me especially if you are getting that result over the web browser... You have no routine that assigns whatever -> whatever in your code, but you are saying you are getting that...
At any rate, this line should be the only one that assigns the value to the output textField...
output_text.text = this.fileName;

snazzyslippers
02-16-2005, 09:36 PM
It makes no sense. I have tried every variation of 'output_text.text = this.fileName'. I keep getting 'undefined'. Let me just try one more clue out on you -- I've been fooling around with traces to see if I can solve it, and I added

for (fileName in this){
trace (fileName+" = "+dataReceiver[fileName]);
output_text.text = fileName;
}


My output textfield displays "onLoad". (?!?) It displays that on my server as well.

And in my output display I get:

successful


fileName = hi
onLoad = [type Function]


fileName -> hi
onLoad -> [type Function]



The above with 'output_text.text = this.fileName' returns 'undefined' in the text field.
The above with 'output_text.text = dataReceiver[fileName]' returns '[type Function] in the text field.


I've been unable to come up with anything that will display the input in the textfield.

Thanks so much,
L


butinst.onRelease = function()
{
var dataSender:LoadVars = new LoadVars();
var dataReceiver:LoadVars = new LoadVars();
dataReceiver.onLoad = function(prm_status:Boolean) {
if (prm_status) {
trace("successful");
for (fileName in this){
trace (fileName+" = "+dataReceiver[fileName]);
output_text.text = fileName;
}

//trace("dataReceiver replay is "+dataReceiver);
for (var prop in dataReceiver) {
trace(prop+" -> "+dataReceiver[prop]);

}

} else {
trace("connecting failed");
}
};
dataSender.file = _level0.input_text.text;
dataSender.sendAndLoad("http://www.worldwidetattoodesigns.com/dynamicout.php",dataReceiver,"POST");
}

deadbeat
02-16-2005, 10:21 PM
It is probably just a scope issue for your text field...

Have you tried:

_level0.output_text.text = fileName;

K.

snazzyslippers
02-16-2005, 10:28 PM
I got it!!

for (fileName in dataReceiver){
trace (fileName+" = "+dataReceiver[fileName]);
}
output_text.text = this.fileName;

When I took the output line out of the brackets it returned the input in my text field.

Who knew? I guess there's something to be said for endless fiddling.

Thanks for all your wonderful help.


Here is what I get now in my output display:

successful
fileName = hooray!


=
onLoad = [type Function]
fileName -> hooray!


->
onLoad -> [type Function]