A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Retrieving variables send with navigateToURL POST method

  1. #1
    Member
    Join Date
    Apr 2001
    Location
    Cape Town
    Posts
    99

    Retrieving variables send with navigateToURL POST method

    I am postin variable to new page using below code. How do I retrieve those variables to add to new textfields?

    var urlReq:URLRequest = new URLRequest("user.html");
    urlReq.method = URLRequestMethod.POST;
    var urlVars:URLVariables = new URLVariables();
    urlVars.var1 = name_txt.text;
    urlVars.var2 = surname_txt.text;
    urlReq.data = urlVars;

    navigateToURL(urlReq,"_self");

  2. #2
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    927
    no way seriosly. in user.html only GET method variables are visible. to handle POST you need to write user.php or other server script.
    who is this? a word of friendly advice: FFS stop using AS2

  3. #3
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    To retrieve the variables you sent to your user.php file, this will help.

    With a button on the stage and 2 textfields, I'm sure you can work out the names of each object, try
    PHP Code:
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.net.URLLoaderDataFormat;

    btn.addEventListener(MouseEvent.CLICKButtonPress);
    function 
    ButtonPress(e:MouseEvent):void
    {
        var 
    DataRequest:URLRequest = new URLRequest("user.php");
        var 
    loader:URLLoader = new URLLoader(DataRequest);
        
    loader.dataFormat URLLoaderDataFormat.VARIABLES;
        
    loader.addEventListener(Event.COMPLETEGetData);
    }

    function 
    GetData(e:Event):void
    {
        
    myText1.text e.target.data.Fromphp1;
        
    myText2.text e.target.data.Fromphp2;

    and with you user.php file in the same directory (in this example), try something simple like so
    PHP Code:
    <?php
        
    echo "Fromphp1=This is the data sent from php part 1.";
        echo 
    "&Fromphp2=This is the data sent from php part 2.";
    ?>

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