A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: loadvars sendandload prob

  1. #1
    Hi, i am attempting to use loadvars to send a variable to a php script, and load back the output from the script. The problem seems to be in the sending part.

    heres my flash script:

    -----------------------------------------------------------------------------------
    thumbNails = new loadvars();
    thumbNails.libraryName=btntext;

    thumbNailsReturn = new loadvars();
    thumbNailsReturn.onLoad = function()
    {
    _root.thumbNailsString=thumbNailsReturn;
    }

    thumbNails.sendAndLoad("http://127.0.0.1/thumbnails.php",thumbNailsReturn,"POST");
    stop();
    -----------------------------------------------------------------------------------

    in my php script, i originally had:
    $libraryName="testimages";

    This is the same as the value stored in btntext. i.e.
    btntext="testimages";

    so in my php script i assumed if i remove $libraryName="testimages";

    since i thought this should be passed from flash, and the php script would work the same. (i.e. i would be able to refer to $libraryname as before) However this doesnt seem to work..

    anybody know what i am doing wrong?

    thx
    bob

  2. #2
    Senior Member
    Join Date
    Feb 2001
    Posts
    1,835
    Hi,

    what you have explained is a little cryptic - however I think that your problem might be in the onLoad function rather than the php.

    Mainly, you should refer to the loadVars object using the 'this' keyword rather than the way you are doing.

    Let's say php is returning a variable called 'status', then use:

    Code:
    ...onLoad = function ()
    {
       trace("returned: " + this.status);
    }
    If you think the problem is with php, just run it in a browser, without any Flash to see what it outputs - that way you can eliminate the possibility of the error being in Flash straight away...

    - n.

  3. #3
    Senior Member
    Join Date
    Mar 2002
    Posts
    142

    Some Possible Hints...

    Problem#1: Do NOT use "()" in the "...onLoad" line:
    Before:thumbNailsReturn.onLoad = function()
    After:thumbNailsReturn.onLoad = function;

    Problem#2: The ordering is important. Perform the "sendAndLoad" BEFORE the "onLoad":
    Before:thumbNailsReturn.onLoad = function;
    thumbNails.sendAndLoad (.....
    After:thumbNails.sendAndLoad (.....
    thumbNailsReturn.onLoad = function;

    Problem#3: You MUST, repeat, you MUST define a variable for thumbNailsReturn to work with. I did NOT see you provide one. (See 'After' below). That's how information is 'Load'ed in Flash.
    Before:thumbNails.sendAndLoad (.....
    thumbNailsReturn.onLoad = function;
    After:thumbNailsReturn.RETVAR = "";
    thumbNails.sendAndLoad (.....
    thumbNailsReturn.onLoad = function;
    ================================================== =======
    PHP Note: I find that I MUST provide a "&" at the end of the return variable during the PHP 'print' statement.
    Do This for example: print "&$var1&";
    Dont do this: print "&$var1"; (No '&' at end of $var)
    ================================================== =======

    I hope that helps.

    Raymond

  4. #4
    Senior Member
    Join Date
    Feb 2001
    Posts
    1,835

    Re: Some Possible Hints...

    Originally posted by rsassine
    ================================================== =======
    PHP Note: I find that I MUST provide a "&" at the end of the return variable during the PHP 'print' statement.
    Do This for example: print "&$var1&";
    Dont do this: print "&$var1"; (No '&' at end of $var)
    ================================================== =======

    I hope that helps.

    Raymond
    Have you checked if you (accidentally) put a line-feed/carriage-return at the end of the string you are printing? Or does 'print' do that automatically? That would cause problems. I don't know anything about PHP really but it seems people here use 'echo' for this kind of thing, rather than print.

    - n.

  5. #5
    Senior Member
    Join Date
    Mar 2002
    Posts
    142
    Thanks for the tip.
    I will try 'echo' in PHP.

    Raymond

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