0
PHP+AS3 Problem
Explorer
,
/t5/animate-discussions/php-as3-problem/td-p/960032
May 04, 2008
May 04, 2008
Copy link to clipboard
Copied
I am trying to send data (variables) to a php file. I keep
getting an error even though I am using the exact method used in
Flash Help (something like
Using External Data).
TOPICS
ActionScript
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/animate-discussions/php-as3-problem/m-p/960033#M25731
May 04, 2008
May 04, 2008
Copy link to clipboard
Copied
Does it trace...
function done(event:Event) {
----------------------------------------->
trace(event.target.data.writing);
tester.text = event.target.data.writing;
}
what does the data.writing do?
"jishi9" <webforumsuser@macromedia.com> wrote in message
news:fvl0qm$a9c$1@forums.macromedia.com...
>I am trying to send data (variables) to a php file. I keep getting an error
> even though I am using the exact method used in Flash Help (something like
> Using External Data).
>
> //////Actionscript 3 (tester is a dynamic textfield on stage)
>
> var req:URLRequest = new URLRequest();
> req.url = "save.php";
> req.method = URLRequestMethod.POST;
> var vars:URLVariables = new URLVariables();
> vars.Name = "some name";
> vars.Comments = "some comment";
> req.data = vars;
>
> var loader:URLLoader = new URLLoader();
> loader.dataFormat = URLLoaderDataFormat.VARIABLES;
> loader.load(req);
> loader.addEventListener(Event.COMPLETE, done);
>
> function done(event:Event) {
> tester.text = event.target.data.writing;
> }
>
>
>
>
> Error: Error #2101: The String passed to URLVariables.decode() must be a
> URL-encoded query string containing name/value pairs.
> at Error$/throwError()
> at flash.net::URLVariables/decode()
> at flash.net::URLVariables$iinit()
> at flash.net::URLLoader/flash.net:URLLoader::onComplete()
>
>
>
> ////////PHP Code (saves data to a text file)
>
> <?php
> //Capture data from $_POST array
> $name = $_POST['Name'];
> $comments = $_POST['Comments'];
> //Make one big string in a format Flash understand
> $toSave ="Name=$name&Comments=$comments;
> //Open a file in write mode
> $fp = fopen("comments.txt", "w");
> if(fwrite($fp, $toSave)) echo "writing=Ok&";
> else echo "writing=Error&"
> fclose($fp);
> ?>
>
function done(event:Event) {
----------------------------------------->
trace(event.target.data.writing);
tester.text = event.target.data.writing;
}
what does the data.writing do?
"jishi9" <webforumsuser@macromedia.com> wrote in message
news:fvl0qm$a9c$1@forums.macromedia.com...
>I am trying to send data (variables) to a php file. I keep getting an error
> even though I am using the exact method used in Flash Help (something like
> Using External Data).
>
> //////Actionscript 3 (tester is a dynamic textfield on stage)
>
> var req:URLRequest = new URLRequest();
> req.url = "save.php";
> req.method = URLRequestMethod.POST;
> var vars:URLVariables = new URLVariables();
> vars.Name = "some name";
> vars.Comments = "some comment";
> req.data = vars;
>
> var loader:URLLoader = new URLLoader();
> loader.dataFormat = URLLoaderDataFormat.VARIABLES;
> loader.load(req);
> loader.addEventListener(Event.COMPLETE, done);
>
> function done(event:Event) {
> tester.text = event.target.data.writing;
> }
>
>
>
>
> Error: Error #2101: The String passed to URLVariables.decode() must be a
> URL-encoded query string containing name/value pairs.
> at Error$/throwError()
> at flash.net::URLVariables/decode()
> at flash.net::URLVariables$iinit()
> at flash.net::URLLoader/flash.net:URLLoader::onComplete()
>
>
>
> ////////PHP Code (saves data to a text file)
>
> <?php
> //Capture data from $_POST array
> $name = $_POST['Name'];
> $comments = $_POST['Comments'];
> //Make one big string in a format Flash understand
> $toSave ="Name=$name&Comments=$comments;
> //Open a file in write mode
> $fp = fopen("comments.txt", "w");
> if(fwrite($fp, $toSave)) echo "writing=Ok&";
> else echo "writing=Error&"
> fclose($fp);
> ?>
>
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
jishi9
AUTHOR
Explorer
,
/t5/animate-discussions/php-as3-problem/m-p/960035#M25733
May 06, 2008
May 06, 2008
Copy link to clipboard
Copied
It never makes it to the done function. I get the error
before after loading the request.
As for the writing variable, it is just a confirmation that the data has been saved.
reply to kglad : as for the php mistake i have corrected it but I still have the same issue.
As for the writing variable, it is just a confirmation that the data has been saved.
reply to kglad : as for the php mistake i have corrected it but I still have the same issue.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/animate-discussions/php-as3-problem/m-p/960034#M25732
May 04, 2008
May 04, 2008
Copy link to clipboard
Copied
you have, at least, one malformed php line:
$toSave ="Name=$name&Comments=$comments;
should be:
$toSave = "Name=" .$name1. "&Comments=" .$comments;
$toSave ="Name=$name&Comments=$comments;
should be:
$toSave = "Name=" .$name1. "&Comments=" .$comments;
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Engaged
,
/t5/animate-discussions/php-as3-problem/m-p/960036#M25734
May 06, 2008
May 06, 2008
Copy link to clipboard
Copied
Remove:
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
This may not solve the problem you are having, but I have seen this causing problems before.
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
This may not solve the problem you are having, but I have seen this causing problems before.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
jishi9
AUTHOR
Explorer
,
/t5/animate-discussions/php-as3-problem/m-p/960037#M25735
May 06, 2008
May 06, 2008
Copy link to clipboard
Copied
When I remove this line, it seems to send (I get an OK in my
textfield) but I don't think the php code correctly receives the
data (it expects variables to be sent to it) and I also get an
error regarding the writing variable:
ReferenceError: Error #1069: Property writing not found on String and there is no default value.
at this_fla::MainTimeline/done()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/flash.net:URLLoader::onComplete()
I think it is necessary to have the DataFormat set to variables in this situation.
ReferenceError: Error #1069: Property writing not found on String and there is no default value.
at this_fla::MainTimeline/done()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/flash.net:URLLoader::onComplete()
I think it is necessary to have the DataFormat set to variables in this situation.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
jishi9
AUTHOR
Explorer
,
/t5/animate-discussions/php-as3-problem/m-p/960038#M25736
May 06, 2008
May 06, 2008
Copy link to clipboard
Copied
Ok I think I understand how I can get this to work. I keep
the dataFormat as Text and then I create a new URLVariables which
decodes the data received from the php file, which seems to work
fine, except for one thing. The data I receive is the actual
contents of the php file, not its echo statements. It seems as if
the php file is not working.I even changed the php file to simply
echo a string, but with no change.
I get this problem both locally and on the server which is php enabled.
Any ideas?
I get this problem both locally and on the server which is php enabled.
Any ideas?
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
jishi9
AUTHOR
Explorer
,
LATEST
/t5/animate-discussions/php-as3-problem/m-p/960039#M25737
May 07, 2008
May 07, 2008
Copy link to clipboard
Copied
Ok I have this code now (I made the php code as simple as
possible so that I can trace the source of the problem easily :
////////////AS3
var req:URLRequest = new URLRequest();
req.url = "save.php";
req.method = URLRequestMethod.POST;
var vars:URLVariables = new URLVariables();
req.data = vars;
var loader:URLLoader = new URLLoader();
trace("begin sending...");
try {
loader.load(req);
} catch (error:Object) {
ttrace(error);
}
loader.addEventListener(Event.COMPLETE, done);
function done(event:Event) {
trace(event.target.data);
}
stop();
//////////////PHP Code
<?php
echo "HI";
?>
/////////Output Panel:
begin sending...
<?php
echo "HI";
?>
////////////////////////////////////////////////////////////////////////DONE
Why am I getting the php file back and not 'HI' from the echo statement?
////////////AS3
var req:URLRequest = new URLRequest();
req.url = "save.php";
req.method = URLRequestMethod.POST;
var vars:URLVariables = new URLVariables();
req.data = vars;
var loader:URLLoader = new URLLoader();
trace("begin sending...");
try {
loader.load(req);
} catch (error:Object) {
ttrace(error);
}
loader.addEventListener(Event.COMPLETE, done);
function done(event:Event) {
trace(event.target.data);
}
stop();
//////////////PHP Code
<?php
echo "HI";
?>
/////////Output Panel:
begin sending...
<?php
echo "HI";
?>
////////////////////////////////////////////////////////////////////////DONE
Why am I getting the php file back and not 'HI' from the echo statement?
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

