0
Processing a PHP variable in AS3
Explorer
,
/t5/animate-discussions/processing-a-php-variable-in-as3/td-p/349165
Apr 05, 2008
Apr 05, 2008
Copy link to clipboard
Copied
I have looked in every book that I have on AS3 and cannot
come up with a solution to this, I hope that someone can help me.
I am receiveing a data string from a PHP --- mySQL connection on my web server. The string is arriving in flash as I can trace it and see the variables. If I do a trace on event.target.data I see the following.
&numResult1=4&numResult2=14&numResult3=37&numResult4=70&numResult5=5&numResult6=3&doneLoading=true
This is exactly what I should be seeing based on my PHP code.
I am trying to assign the numResult numbers to a dynamic text box, for instance numResult1 = 4, I would like to assign that 4 to a dynamic text field on the Flash Stage. I have not figured out a way to get the variable out of the string.
I keep getting undefined or a variety or other errors with the different methods I try.
I have tried numerous ways using the URLVariables class but I have had no luck. Use to be very simple in AS2, I could assign the variable right to the dynamic text field in the properties panel, not anymore.
Does anyone know how I can do this. People are doing it all the time, it can't be that hard, is it?????
Just a good example as to how to break the variables out would be really helpful. I have tried the FlashGods site and could not figure there examples out, in fact the two I tried did not work at all.
I would appreciate any help.... Thank you.
Mike
I am receiveing a data string from a PHP --- mySQL connection on my web server. The string is arriving in flash as I can trace it and see the variables. If I do a trace on event.target.data I see the following.
&numResult1=4&numResult2=14&numResult3=37&numResult4=70&numResult5=5&numResult6=3&doneLoading=true
This is exactly what I should be seeing based on my PHP code.
I am trying to assign the numResult numbers to a dynamic text box, for instance numResult1 = 4, I would like to assign that 4 to a dynamic text field on the Flash Stage. I have not figured out a way to get the variable out of the string.
I keep getting undefined or a variety or other errors with the different methods I try.
I have tried numerous ways using the URLVariables class but I have had no luck. Use to be very simple in AS2, I could assign the variable right to the dynamic text field in the properties panel, not anymore.
Does anyone know how I can do this. People are doing it all the time, it can't be that hard, is it?????
Just a good example as to how to break the variables out would be really helpful. I have tried the FlashGods site and could not figure there examples out, in fact the two I tried did not work at all.
I would appreciate any help.... Thank you.
Mike
TOPICS
ActionScript
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/processing-a-php-variable-in-as3/m-p/349166#M9504
Apr 05, 2008
Apr 05, 2008
Copy link to clipboard
Copied
your urlloader has a data property which has numResult1 and
numResult2 etc properties.
you'll probably need to cast your urlloader's data property as a urlvariable.
you'll probably need to cast your urlloader's data property as a urlvariable.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Mike_King
AUTHOR
Explorer
,
/t5/animate-discussions/processing-a-php-variable-in-as3/m-p/349167#M9505
Apr 06, 2008
Apr 06, 2008
Copy link to clipboard
Copied
I have been trying to work this through for over a week, here
is the ActionScript Code;
AS
function getData(event:Event):void {
var myURLLoader:URLLoader = new URLLoader();
var myURLRequest:URLRequest = new URLRequest("polls2.php"); // Actually goes to a web site.
myURLLoader.dataFormat=URLLoaderDataFormat.TEXT;
myURLLoader.load(myURLRequest);
myURLLoader.addEventListener(Event.COMPLETE, completeHandler);
function completeHandler(event:Event):void {
trace(myURLLoader.data);
var myURLVariables:URLVariables = new URLVariables(myURLLoader.data);
}
gotoAndStop(2);
}
Here is what I get with the Trace Statement:
&numResult1=6&numResult2=6&numResult3=5&numResult4=9&numResult5=7&numResult6=1&doneLoading=true
Here is what I get when I try to set the URL variables.
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()
at MethodInfo-2()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
Now it sure looks to me that the string being passed is name/value pairs.
I have tried every way that I can think of to capture this data. I must be missing something simple.
Any ideas would be greatly appreciated.
Thanks for your help.
Mike
AS
function getData(event:Event):void {
var myURLLoader:URLLoader = new URLLoader();
var myURLRequest:URLRequest = new URLRequest("polls2.php"); // Actually goes to a web site.
myURLLoader.dataFormat=URLLoaderDataFormat.TEXT;
myURLLoader.load(myURLRequest);
myURLLoader.addEventListener(Event.COMPLETE, completeHandler);
function completeHandler(event:Event):void {
trace(myURLLoader.data);
var myURLVariables:URLVariables = new URLVariables(myURLLoader.data);
}
gotoAndStop(2);
}
Here is what I get with the Trace Statement:
&numResult1=6&numResult2=6&numResult3=5&numResult4=9&numResult5=7&numResult6=1&doneLoading=true
Here is what I get when I try to set the URL variables.
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()
at MethodInfo-2()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
Now it sure looks to me that the string being passed is name/value pairs.
I have tried every way that I can think of to capture this data. I must be missing something simple.
Any ideas would be greatly appreciated.
Thanks for your help.
Mike
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/processing-a-php-variable-in-as3/m-p/349168#M9506
Apr 06, 2008
Apr 06, 2008
Copy link to clipboard
Copied
yes, but you didn't inform your loader that it was receiving
variable/value pairs. it thinks it's receiving text (the default
dataformat). try:
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Guru
,
/t5/animate-discussions/processing-a-php-variable-in-as3/m-p/349169#M9507
Apr 06, 2008
Apr 06, 2008
Copy link to clipboard
Copied
This was already solved over at flashgods.org.
The URLVariables was not the main issue. You can set the URLLoader's dataFormat to URLLoaderDataFormat.VARIABLES. And I believe you still need to cast the data property as a URLVariables before accessing the values (I didn't try not doing that).
Beyond that, the issue was the urlencoded string having a prepended ampersand.
You can get away with a prepended ampersand in as2 with LoadVars (although I never do that) but apparently in as3 you can't. The urlencoded values need to match what you would see in the browser address bar after the ?, i.e. no initial ampersand.
The URLVariables was not the main issue. You can set the URLLoader's dataFormat to URLLoaderDataFormat.VARIABLES. And I believe you still need to cast the data property as a URLVariables before accessing the values (I didn't try not doing that).
Beyond that, the issue was the urlencoded string having a prepended ampersand.
You can get away with a prepended ampersand in as2 with LoadVars (although I never do that) but apparently in as3 you can't. The urlencoded values need to match what you would see in the browser address bar after the ?, i.e. no initial ampersand.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Mike_King
AUTHOR
Explorer
,
LATEST
/t5/animate-discussions/processing-a-php-variable-in-as3/m-p/349170#M9508
Apr 07, 2008
Apr 07, 2008
Copy link to clipboard
Copied
Working through the Live Support at Flash Gods they helped me
work through the issue.
The data string included an ampersand at the beginning of the string, once I modified the PHP code to remove that ampersand the data was processed as expected.
This was an interesting one. I am not certain that I would have ever thought about that character causing the issue.
I appreciate all the responses to the post.
Thanks.
The data string included an ampersand at the beginning of the string, once I modified the PHP code to remove that ampersand the data was processed as expected.
This was an interesting one. I am not certain that I would have ever thought about that character causing the issue.
I appreciate all the responses to the post.
Thanks.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

