Button Script to Function

Hi, how can I take the following script which is attached to a button and separate it onto it’s own frame?

[AS]
on (release, keyPress “<Enter>”) {
if (email eq “”) {
stop ();
} else {
loadVariablesNum (“form.php”, 0, “POST”);
this.thanks.text = “Thank You!”;
}
}
[/AS]

if (email == "") {
                stop ();
        } else {
                loadVariablesNum ("form.php", 0, "POST");
                this.thanks.text = "Thank You!";
        }

But is there a way to remove the onRelease handler from the button as well so there is no script attached to the button but just connected via instance name?


myMCname.onRelease = function(){
if (email == "") {
        stop ();
} else {
        loadVariablesNum ("form.php", 0, "POST");
        this.thanks.text = "Thank You!";
}
}
myListener = new Object();
myListener.onKeyDown = function () {
	if(Key.isDown(Key.ENTER)){
		myMCname.onRelease();
	}
}
Key.addListener(myListener);

Hello,

Is there a way to have the textfield display “transmitting” when the email is being sent and then thank you when it’s complete? :red:


myMCname.onRelease = function() {
	if (email == "") {
		stop();
	} else {
		this.thanks.text = "transmitting";
		sendVar = new LoadVars();
		getVar = new LoadVars();
		sendVar.email = email;
		getVar.onLoad = function(success) {
			if (success) {
				myMCname.thanks.text = this.stat;
			} else {
				myMCname.thanks.text = "error";
			}
		};
		sendVar.sendAndLoad("form.php", getVar, "POST");
		this.thanks.text = "Thank You!";
	}
};

this is going to be a little different from LoadVariablesNum. All the variables that you want sent must be defined in the sendVar object, and whatever var name you give them in the sendVar object, that’s what the post var will be for example:
sendVar.myVar = theEmail;
the var that will be send to the page via post will be ‘myVar’ but with the value of ‘theEmail’. Also all variables that are being recieved will be located in the getVar object. They will be stored in the same manner as the sendVar object.
getVar.stat ;
if there is a returning variable (from the php page) the will all be stored in the getVar object. So Have you php page return a value for stat. For example:

print "&stat=Thank You!"

that should work. :slight_smile: