简体   繁体   中英

Flash to PHP : Vars don't pass in SWF file

I'm doing an Actionscript 3 script (with Flash 13) that takes a user's email and then sends it to a PHP file on my website, and the PHP file formats an email wich it sends to the user's address. Nothing too complicated, and when I test it in Flash it works just fine. But as soon as I export the movie, it doesn't seem to be able to "contact" the PHP file anymore. The PHP file has an error handling condition, and since I receive no email at all, I know the problem is with Flash.

I tried hosting the Flash file, embedded in a web page, on the same server as the PHP file, with no results.

Here's my AS code :

myEmail = result.text;

var myData:URLRequest = new URLRequest("http://www.mywebsite.com/sendmail.php");
myData.method = URLRequestMethod.GET;

var variables:URLVariables = new URLVariables();
variables.email = myEmail;
myData.data = variables;

var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, dataOnLoad);  // the dataOnLoad functions only does a trace
loader.load(myData);

And my PHP :

if (!empty($_GET)) {
    $to = $_GET['email'];
    $message = "Hurray !!!";
    mail($to, 'Here is your coupon !', $coupon);
} else {
    mail('me@mysite.com', 'Error', 'Your GET info is faulty my friend');
}

Is there some restriction to these functions I should be aware of ? Or an option to check when exporting the movie ?

Thank you all for your help !

Below is a script which will load your variables into an array. I use this to pass vars from php to AS3 flash swf file using:"$returnString = http_build_query ($returnVars);".

FLASH

    var myarray;
    var loader:URLLoader = new URLLoader();
    var request:URLRequest = new URLRequest("http://www.mywebsite/thescript.php");
    request.method = URLRequestMethod.GET;
    trace("loadingScript");
    loader.dataFormat = URLLoaderDataFormat.VARIABLES;
    loader.addEventListener(Event.COMPLETE, completeHandler);
    loader.load(request);
        //you set up your listeners and add:

   function completeHandler(evt:Event)
   {

   var intiCount = 0;
   for each (var obj:Object in evt.target.data)
   {
    myarray.push(obj);// each item will be pushed into array
    intiCount++;
            trace(myarray[i]) ;  // i= will loop each item i= 0,1,2
                               // output:  whatever1, what ever2 ,what ever 3.

       }
   }

PHP SCRIPT:

    <?php
    $returnVars['item1'] = "whatever1";
    $returnVars['item2'] = "whatever2";
    $returnVars['item3'] = "whatever3";
    $returnString = http_build_query($returnVars);
    echo $returnString;
    //the items are now in key pairs in flash.
    ?>

尝试将单引号发送到php ...我遇到了同样的问题,并且在调用文件时必须尝试过大约100个不同的版本...如此才能使其正常工作... try >>'../ yourphp.php”

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM