# Converting code from AS1 to AS3

**URL:** <https://forum.kirupa.com/t/converting-code-from-as1-to-as3/315027>\
**Category:** flash\
**Created:** [October 15, 2010, 2:59pm UTC](https://forum.kirupa.com/t/converting-code-from-as1-to-as3/315027 "2010-10-15T14:59:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wolfenr](https://avatars.discourse-cdn.com/v4/letter/w/8e7dd6/32.png) [@wolfenr](https://forum.kirupa.com/u/wolfenr)\
**Post date:** [October 15, 2010, 2:59pm UTC](https://forum.kirupa.com/t/converting-code-from-as1-to-as3/315027/1 "2010-10-15T14:59:59Z")

</div>

Hi all you clever people and hope you can help.

I’m trying to convert some AS1 code into AS3, it is a contact form and, mostly I’ve got it sorted but struggling with a couple of lines and am wondering if any of you can help. Oh, by the way, the code works fine as AS1.

Here’s my part converted code with my problem areas highlighted in red…

stop();  
send\_btn.addEventListener(MouseEvent.CLICK, sendMessage);  
function sendMessage(e:MouseEvent):void{  
var my\_vars:URLVariables = new URLVariables();  
my\_vars.name = name\_box.text;  
my\_vars.sender = email\_box.text;  
my\_vars.tel = tel\_box.text;  
my\_vars.subject = subject\_box.text;  
my\_vars.message = message\_box.text;

if (my\_vars.sender != “” && my\_vars.subject != “” && my\_vars.message != “” && my\_vars.name !="") {  
my\_vars.sendAndLoad(“mailer.php”, my\_vars, “POST”);  
gotoAndStop(2); // gives user feedback on send progress.  
} else {  
error\_clip.gotoAndPlay(2);  
}  
[COLOR=red]my\_vars.onLoad = function()[/COLOR] {  
gotoAndStop(3); // tells them the email has been sent.  
}  
}  
[COLOR=red]email\_box.onSetFocus = subject\_box.onSetFocus=message\_box.onSetFocus=function ()[/COLOR] {  
if (error\_clip.currentframe != 1) {  
error\_clip.gotoAndPlay(19); // tells them to try filling in the fields again.  
}  
}

So of the 2 highlighted areas, the 1st one I don’t really understand the function () statement but AS3 doesn’t generate errors for this. The second chunk of code does generate errors.

Any help would be appreciated, thanks for reading this.  
Rog
