Go Back   kirupaForum > Flash > ActionScript 3.0

Reply
 
Thread Tools Display Modes
Old 11-29-2009, 07:04 AM   #1
dimsum
Registered User
Afrostyle Flash AS 3.0 error- submitting data to a database using PHP.

Hello,

I am trying to establish a connection between my swf and a database using PHP. I keep getting the following error:

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 cursors_fla::MainTimeline/sendHandler()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunctio n()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/flash.net:URLLoader::onComplete()


My actionscript exists on the timeline and looks like this:

import flash.net.*;
import flash.display.Loader;

var loader:URLLoader = new URLLoader();

submittophp();

function submittophp(){
var variables:URLVariables = new URLVariables();
var urlRequest:URLRequest = new URLRequest("http://path/request.php");

urlRequest.method = URLRequestMethod.POST;

variables.pos="values";
trace(variables);
urlRequest.data=variables;
trace(urlRequest.data);

loader.dataFormat=URLLoaderDataFormat.TEXT;
loader.addEventListener(Event.COMPLETE,sendHandler );
loader.load(urlRequest);
trace("reached load command end!!!");
}

function sendHandler(evt:Event):void {
loader = URLLoader(evt.target);
var variables:URLVariables = new URLVariables(loader.data);
trace("reached sendHandler!");
}

function dataOnLoad(evt:Event){
trace(evt.target.data); //status is a custom flag passed from back-end
trace("reached dataOnLoad!");
}


From troubleshooting the file locally, I was able to verify that while the PHP url is loaded, Flash doesn't reach the function sendHandler. I loaded the file on my ftp but nothing was received by the database.

Can anyone determine what is wrong? Thanks!
dimsum is offline   Reply With Quote

Sponsored Links (Guests Only) - Register | Need Help?
 

Old 11-29-2009, 07:12 AM   #2
IqAndreas
Registered User
Location Värmland, Sweden (and Illinois, USA)

Posts 1,329
Remove "new" in this line, so it looks like this:
var variables:URLVariables = URLVariables(loader.data);

What you are doing is not recreating a new "URLVariables", you are treating the already existing as a URLVariables.


EDIT: Never mind. I didn't read the code well enough. Try tracing out "loader.data" to see what it looks like. That is the line causing the code, so Flash apparently doesn't like whatever is inside of that string.

__________________
Give someone code, and they will have code for a day.
Teach someone to code, and they will have code for life.

Support a starving developer. Click ads in my blog...
http://iqandreas.blogspot.com/
IqAndreas is online now   Reply With Quote
Old 11-29-2009, 12:52 PM   #3
dimsum
Registered User
Quote:
Originally Posted by IqAndreas View Post
Remove "new" in this line, so it looks like this:
var variables:URLVariables = URLVariables(loader.data);

What you are doing is not recreating a new "URLVariables", you are treating the already existing as a URLVariables.


EDIT: Never mind. I didn't read the code well enough. Try tracing out "loader.data" to see what it looks like. That is the line causing the code, so Flash apparently doesn't like whatever is inside of that string.
SOMETHING WORKED!!!

So I tried both things anyway-

1. removing new from the URLvariables statement produced this error. :

//"empty string??Pritikaaatest " is being echoed from the PHP file

TypeError: Error #1034: Type Coercion failed: cannot convert "empty string??Pritikaaatest " to flash.net.URLVariables.
at cursors_fla::MainTimeline/sendHandler()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunctio n()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/flash.net:URLLoader::onComplete()


So I figured that I needed to adjust the code so that variables.pos was accepting lodaer.data instead.I also put 'new' back in the declaration of new URLvariables().I modified the sendHandler function to this:

function sendHandler(evt:Event):void {
trace("reached sendHandler!");

var loader:URLLoader = URLLoader(evt.target);
trace(loader.data);
var variables:URLVariables = new URLVariables();
variables.pos=loader.data;
trace(variables);

}

I also changed my php file a bit and now I see that not only are there no errors, data is being submitted from the flash file to the database!! woohoo!

Thank you

Last edited by dimsum; 11-29-2009 at 01:29 PM..
dimsum is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:45 PM.

SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple. flash components
Creative web apps. Make your own free flash banners and photo slideshows.
Check out the great, high-quality flash extensions. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.

Flash Transition Effects

Flash Effect Tutorials

Digicrafts Components
Flash effects. Art without coding. Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com
Streamsolutions Content Delivery Networks Flipping Book - page flip flash component.
Flash-Gallery.com - Get your flash photo gallery (flash component or swf gallery Learn how to advertise on kirupa.com
 

cdn
content delivery network (cdn)

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Copyright 2010 - kirupa.com Copyright 2010 - kirupa.com