A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Get variables back when uploading file

  1. #1
    Junior Member
    Join Date
    Jul 2009
    Posts
    15

    Get variables back when uploading file

    Hi

    I can successfully get variables back into AIR when communication just using variables, but get errors when trying to get vars back after a successful upload.

    Here is some non-upload code that works perfectly giving me vars back:

    function login(event:Event):void {

    u_username = login_user.text;
    u_password = login_pass.text;
    var myrequest:URLRequest = new URLRequest("http://www.blah.net/login.php");
    myrequest.method = URLRequestMethod.POST;
    var variables:URLVariables = new URLVariables();
    variables.user_name = u_username;
    variables.user_pass = u_password;
    myrequest.data = variables;
    var loader:URLLoader = new URLLoader();
    loader.dataFormat = URLLoaderDataFormat.VARIABLES;
    loader.addEventListener(Event.COMPLETE, loginStatus);
    //loader.addEventListener(IOErrorEvent.IO_ERROR, onError);
    loader.load(myrequest);
    }

    function loginStatus(event:Event) {

    code = event.target.data.var1;
    tokenVar = event.target.data.tokenVar;
    }

    Relevant php:

    print "var1=$user_code&tokenVar=$tokenVar";
    ------------------------------------------------------------

    When I use upload code, I get the error:
    TypeError: Error #1009: Cannot access a property or method of a null object reference.

    Here's the upload function:

    function testerFunction(event:Event):void {

    var URLrequest:URLRequest = new URLRequest("http://www.blah.net/uploader.php/");
    URLrequest.method = URLRequestMethod.POST;
    var variables:URLVariables = new URLVariables();
    variables.user_name = user_name;
    variables.tokenVar = tokenVar;
    URLrequest.method = URLRequestMethod.POST;
    URLrequest.data = variables;
    newFile.addEventListener(Event.COMPLETE, editStatus);
    newFile.upload(URLrequest);
    }


    function editStatus(event:Event):void {

    var editUpdate = event.target.data.var1;
    trace (editUpdate);
    }

    relevant php:

    print "var1=upload successful";
    ---------------------------------------------------------

    Everything except the var return works fine - the file is uploaded and saved no problem, and in the php the print "var1=upload successful"; code comes right after the code that saves the file to the server.

    Is there a way to use...

    var loader:URLLoader = new URLLoader();
    loader.dataFormat = URLLoaderDataFormat.VARIABLES;

    ...when uploading a file, as that seems to be the main difference.

    Thanks for your time and help.

    Shaun

  2. #2
    Senior Member guardiankitty's Avatar
    Join Date
    Dec 2006
    Location
    Here
    Posts
    215
    Honestly I have not played with this much (at least not for years), however here is some of my basic trouble shooting.


    I notice the PHP script reads:
    PHP Code:
    print "var1=upload successful"
    try changing that to read:
    PHP Code:
    print "var1=upload successful&"
    This caps off the variable and I remember a while back having an issue close to what you are describing and this fixed it.


    Then next I would try setting a value like "variables.var1 = true;" then seeing if that value is getting nulled or if it stays true till after the loading of the variables.


    If nether of these work, then I guess I got to do a little more homework and try and recreate this issue on my end.

    As far as the code you are using, nothing is jumping out at me as explicitly wrong.


    Hope that helps,
    -GK >^_^<

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center