A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Cross domain help

  1. #1
    Dance Monkey Dance! Doush.'s Avatar
    Join Date
    Jun 2004
    Posts
    254

    Cross domain help

    Hey all, having a few problems with calling a php script on another domain from a flash file on a different domain. Here's the scenario.

    I have a domain that doesn't support PHP (yeah tell me about it) and on this domain I have a flash file which has a contact form. The code for the form is as follows.

    So on the fla on site1.com I have this,

    PHP Code:
    message = new LoadVars();
    messageSent = new LoadVars();

    messageSent.onLoad = function() {
        
        
    trace(this.sent);
        
        if(
    this.sent == "OK") {
            
    name_txt.text '';
            
    email_txt.text '';
            
    subject_txt.text '';
            
    message_txt.text "Message sent";
        }else{
            
    name_txt.text '';
            
    email_txt.text '';
            
    subject_txt.text '';
            
    message_txt.text this.reason;
        }
    }

    bu_send.onRelease = function() {
        
        
    msgError false;
        
        if(
    name_txt.text == '' || name_txt.text == "Please enter a name") {
            
            
    name_txt.text "Please enter a name";
            
    msgError true;
            
        }
        
        if(
    email_txt.text == '' || email_txt.text == "Please enter an email") {
            
            
    email_txt.text "Please enter an email";
            
    msgError true;
            
        }
        
        if(
    subject_txt.text == '' || subject_txt.text == "Please enter a subject") {
            
            
    subject_txt.text "Please enter a subject";
            
    msgError true;
            
        }
        
        if(
    message_txt.text == '' || message_txt.text == "Please enter a message") {
            
            
    message_txt.text "Please enter a message";
            
    msgError true;
            
        }
        
        
        if(
    msgError == false) {
            
            
    message.name name_txt.text;
            
    message.email email_txt.text;
            
    message.subject subject_txt.text;
            
    message.msg message_txt.text;
            
            
    message.sendAndLoad("http://site2.com.au/mailer.php"+ new Date().getTime(), messageSent);
            
        }

    Now its calling the mailer.php script from site2.com which the code is like this

    PHP Code:
    <?php

        $to 
    "admin@site1.com.au";
        
        
    $name $_POST['name'];
        
    $email $_POST['email'];
        
    $subject $_POST['subject'];
        
    $message "Name: ".$name."\n\n";
        
    $message .= "Email: ".$email."\n\n";
        
    $message .= "Message ".$_POST['msg'];
        
    $subject $_POST['subject'];
        
    $header "From: Site 1 - ".$name."<emailer@site1.com>\n";
        
        
    $OK mail($to,$subject,$message,$header);
        
        if(
    $OK) {
            echo 
    'sent=OK';
        }else{
            echo 
    'sent=failed&reason='.urlencode('There seems to be a problem with the server. Please try later.');
        }

    ?>
    Now when this is all running off the one domain It sends fine but because PHP isn't enabled I'm trying to run the script off another site. I was pretty sure you can do this. But its proving pretty hard. I even opened up for all sites using a cross domain script but, All i get returned is undefined and in flash it says error opening url.

    I tried several different cross domain polities, the one I have up at the moment is,

    Code:
    <cross-domain-policy> 
        <allow-access-from domain="*"/>
    </cross-domain-policy>
    Anyone have a clue how to do this or a better way to do it would be great.

    Thanks in advance
    "I layed down in my bed last night looked up at the stars, and thought to myself... Where the F*#K is my roof"

  2. #2
    Junior Member
    Join Date
    Aug 2008
    Location
    London village
    Posts
    8
    Hmm, that all looks okay assuming the crossdomain file is on the same server as the PHP?

    Just looking at the AS you have there

    Code:
    message.sendAndLoad("http://site2.com.au/mailer.php"+ new Date().getTime(), messageSent);
    It probably won't like the date being appended right after the php without a ? separating it... eg

    Code:
    message.sendAndLoad("http://site2.com.au/mailer.php?"+ new Date().getTime(), messageSent);

  3. #3
    Dance Monkey Dance! Doush.'s Avatar
    Join Date
    Jun 2004
    Posts
    254
    Haha stupid me, that was it. Thanks heaps. I'm almost bald from pulling my hair out.
    "I layed down in my bed last night looked up at the stars, and thought to myself... Where the F*#K is my roof"

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