Skip to main content
Known Participant
February 15, 2010
Answered

Coverting as2 to as3

  • February 15, 2010
  • 1 reply
  • 2212 views

Hi all,

I have an as2 emailer form on my site and i would like to convert it to as3. (ive blanked out the web address and email as its a private thing for clients).

Please can I have some help!? (novice at as3)

Thank you!

Dan

This is the code from the fla;

var senderLoad:LoadVars = new LoadVars();
var receiveLoad:LoadVars = new LoadVars();

sender.onRelease = function() {
senderLoad.theName = theName.text;
senderLoad.theEmail = theEmail.text;
senderLoad.theMessage1 = theMessage1.text;
senderLoad.theMessage2 = theMessage2.text;
senderLoad.theMessage3 = theMessage3.text;
senderLoad.theMessage4 = theMessage4.text;
senderLoad.theMessage5 = theMessage5.text;
senderLoad.theMessage6 = theMessage6.text;
senderLoad.sendAndLoad("http://www....../sendLL.php",receiveLoad);
}


receiveLoad.onLoad = function() {
if(this.sentOk) {
  getURL("http://www....../LL-sent.html", "_self");
}
else {
  getURL("http://www......./LL-failed.html", "_self");
}
}

This is the code from the php;

<?PHP

$to = "email@notelling.com";
$subject = "Lyric Lounge Viewing Panel Comments";
$message = "Name: " . $theName;
$message .= "\nEmail: " . $theEmail;
$message .= "\n\nWhat do you like the least? \n" . $theMessage1 . "\n";
$message .= "\n\nWhat do you like the most? \n" . $theMessage2 . "\n";
$message .= "\n\nWhat element would you expand? \n" . $theMessage3 . "\n";
$message .= "\n\nHow could it be improved? \n" . $theMessage4 . "\n";
$message .= "\n\nOther Comments \n" . $theMessage5 . "\n";
$message .= "\n\nRating \n" . $theMessage6 . "/10";
$headers = "From: $theEmail";
$headers .= "\nReply-To: $theEmail";

$sentOk = mail($to,$subject,$message,$headers);

echo "sentOk=" . $sentOk;

?>

This topic has been closed for replies.
Correct answer

Thank you for your help dmennenoh.

I still cant seem to get it working.

I originally got it from this website http://www.gotoandlearn.com/play?id=50

The PHP with the boolean value sentOk is at about 19 minutes

Basically the PHP only sents back a bollean if it sends ok.

So in AS3 i need to make it so it can get that value and if so, go onto load the success page.

I have followed what you have said and its still not working?!

also, if i remove the var from the front of the send function then it throws up a load of errors.

So close but yet seemling so far!

Thanks for your help...appreciate it.


Dan


Here, this should get you going.

sender.addEventListener(MouseEvent.CLICK, Send);

var loader:URLLoader = new URLLoader(); //put loader outside the function so it is available in sent


function Send(ev:MouseEvent):void {
   var req:URLRequest = new URLRequest("http://www......sendLL.php");
   var vars:URLVariables = new URLVariables();
  
   
vars.theName = theName.text;
vars.theEmail = theEmail.text;
vars.theMessage1 = theMessage1.text;
vars.theMessage2 = theMessage2.text;
vars.theMessage3 = theMessage3.text;
vars.theMessage4 = theMessage4.text;
vars.theMessage5 = theMessage5.text;
vars.theMessage6 = theMessage6.text;
     
   req.method = URLRequestMethod.POST;
   req.data = vars;
  
   loader.dataFormat = URLLoaderDataFormat.VARIABLES;

   loader.addEventListener(Event.COMPLETE, emailSent, false, 0, true); //add listener to call sent
   loader.load(req); 


}

function emailSent(e:Event):void

{

     trace(loader.data.sentOK);

}

1 reply

Ned Murphy
Legend
February 15, 2010

Try searching Google using "AS3 URLVariables" as a search term for the form end of things--there should be a few tutorials out there.  Look into navvigateToURL() as the AS3 replacement for AS2's getURL().

Known Participant
February 15, 2010

Hi again Ned. Cheers for the help,

Ive taken your advice and tried to convert it.

There are no errors, but nothing happens when you click the send button!

Can you see any problems with my code?

also am i going to have to change anything within the PHP?

Cheers

Dan

This is my converted code;

stop();

sender.addEventListener(MouseEvent.CLICK, Send);
function Send(ev:MouseEvent):void {
   var req:URLRequest = new URLRequest("http://www....sendLL.php");
   var vars:URLVariables = new URLVariables();
   var loader:URLLoader = new URLLoader();
   
vars.theName = theName.text;
vars.theEmail = theEmail.text;
vars.theMessage1 = theMessage1.text;
vars.theMessage2 = theMessage2.text;
vars.theMessage3 = theMessage3.text;
vars.theMessage4 = theMessage4.text;
vars.theMessage5 = theMessage5.text;
vars.theMessage6 = theMessage6.text;
     
   req.method = URLRequestMethod.POST;
   req.data = vars;
  
   loader.dataFormat = URLLoaderDataFormat.VARIABLES;
  
if(this.sentOk) {
  var url:String = ("http://www...../LL-sent.html");
}
else {
  var url2:String =("http://www....../LL-failed.html", "_self");
}
}

Ned Murphy
Legend
February 15, 2010

Have you put a trace in the Send function to see if it gets that far?