Results 1 to 3 of 3

Thread: Flash AS 3.0 error- submitting data to a database using PHP.

  1. #1

    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!

  2. #2
    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.
    Blog article of the month: Why My One Line 'if' Statements Are Unusual
    Twitter: @IQAndreas
    GitHub: IQAndreas

  3. #3
    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; November 29th, 2009 at 01:29 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012