Search code examples
flashactionscriptpostrequestpublish

flash, actionscript - the post request from a flash file stops working after published


Good day to all. I have a problem with the following code:

textBox.addEventListener(KeyboardEvent.KEY_DOWN,handler);
   function handler(event:KeyboardEvent){

   // if the key is ENTER
   if(event.charCode == 13){

    var url:String = "http://localhost/flashsave.php";
    var request:URLRequest = new URLRequest(url);

    var variables:URLVariables = new URLVariables();

    variables.cuvant = textBox.text;

    request.data = variables;
    request.method = URLRequestMethod.POST;

    navigateToURL(request);
    var loader:URLLoader = new URLLoader();

    try {
        loader.load(request);
    } catch (error:Error) {
        //trace("Unable to load requested document.");
    }

The problem is that the code is working when I test the scene (ctr+alt+enter in flash), but after I publish it it doesn't work... not sending any request nor redirect.

What I want to do is to log in a file on the server what the users typed (related with Related with: Flash actionscript - save a text file on server).

Thank you for help.


Solution

  • I believe that have a static link to the localhost like that is your problem. Try having your swf in one directory and the php in the same directory or in a subdirectory.

    if the php is in the same directory its url would be:

    "flashsave.php"
    

    Else if it is in a subdirectory it would be:

    "php/flashsave.php"
    

    do not include a forward slash at the start of the link as it will reference the C:// drive :)