A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: AS3 pass value to ASP...

  1. #1
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,930

    AS3 pass value to ASP...

    Hmmm...

    I have a flash file that's on an ASP 3.0 page. When the user finishes the interactions on the flash page, I need to post back to the current page and pass a variable so the system goes to the results page.

    I'm currently doing this (POSTing the value and then navigating to the page), but it doesn't seem to work consistently. Sometimes it passes the "choice" 1 value, sometimes it doesn't...any ideas??

    Code:
    //pageURL is the current page URL and is being correctly set via ExternalInterface
    function writeScore()
    {
    	
    var scriptRequest:URLRequest = new URLRequest(pageURL);
        var scriptLoader:URLLoader = new URLLoader();
        var scriptVars:URLVariables = new URLVariables();     
        scriptLoader.addEventListener(Event.COMPLETE, handleLoadSuccessful);
        scriptLoader.addEventListener(IOErrorEvent.IO_ERROR, handleLoadError);     
        scriptVars.choice = 1;
        scriptRequest.method = URLRequestMethod.POST;
        scriptRequest.data = scriptVars;
        scriptLoader.load(scriptRequest);     
        function handleLoadSuccessful($evt:Event):void
        {
            trace("Message sent.");
    		var url:String;
    		url = pageURL; 
    		var request:URLRequest = new URLRequest(url);
    		try
    		{
    			navigateToURL(request, '_self');
    		}
    		catch (e:Error)
    		{
    			trace("Error occurred!");
    		}
        }
         
        function handleLoadError($evt:IOErrorEvent):void
        {
            trace("Message failed.");
        }
    }
    Is there another way to navigate to a URL and pass a variable without using a GET and putting it in the URL?

    Thanks!
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  2. #2
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    would there be a problem to just send the post data to the new page within a navigateToUrl request? Of course this means that you wouldn't have a chance to see whether the server page handled the data, but it is more in line with the way asp pages are typically set up

    Musicman

  3. #3
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,930
    Almost, but I can't have it include the variable in the URL, which was why I was trying the POST in combination with the navigateToURL, but that doesn't seem to be consistent...
    hmmm...
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  4. #4
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    is there any way that you could inspect data passing from flash to your server script or verify what the server script does?
    If it is not https, wireshark should be able to look at the data. You should see
    a) your data as POST data, and most likely a cookie that asp was setting earlier
    b) a Location response
    c) the browser loading that page

    Musicman

  5. #5
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,930
    Hmm...unfortunately, I'm not doing the back-end and can just upload the file and test it without being able to do anything on the asp side.

    Shouldn't the POST and navigateToURL combination work? I'm thinking that it might be passing the variable in POST but when it does the navigateToURL it's losing the variable somehow? Surely there's a way to have flash send the user to a URL and pass a variable at the same time without having to use the URL?
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  6. #6
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    it is not a combination of two requests - it should be one single navigateToUrl request, with the POST method and data in the URLRequest object

    Musicman

  7. #7
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,930
    Ah, that was it. Somehow, I thought I needed to do the POST separate from the navigate, not realizing that it's just setting the method.

    Working great now!! Thanks!!
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

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