PDA

View Full Version : Simple email function question??



keitai
July 20th, 2006, 07:54 AM
So I created this simple function


function emailTo(address):Void {
var address:String;
getURL("mailto:"+address);
}



Now I know this works


mail_btn.onRelease = function () {
this.address = "test@domain.com";
emailTo(this.address);
}



But I want it to be in this format

mail_btn2.onRelease = emailTo("test@domain.com");

But now it opens up my email program as soon as I test the flash file, so not on click

Any ideas??

creatify
July 20th, 2006, 12:20 PM
When a function is called in this manner - where you're passing the function an argument, it gets executed when that line is read by the player:

mail_btn2.onRelease = emailTo("test@domain.com");

you could do some thing like this though, where you store the email adress in a variable within your button, this should work fine.


function emailTo():Void {
// if you trace 'this' - it will trace out your actual button
// trace(this)
// scope changes when calling this method from
// and event handler

// so you can retreive the address stored in the button variable
var eml:String = this.emlAdd;
getURL("mailto:"+eml);

//this would also work of course
//getURL("mailto:"+this.emlAdd);

}

// store the address in the button variable
mail_btn2.emlAdd = "test@domain.com";

// set onRelease equal to your function without "()" so it isn't executed right away.
mail_btn2.onRelease = emailTo;

keitai
July 20th, 2006, 12:30 PM
ah tx, works like a charm

What I also tried was



emailTo.address = "test@domain.com"


Which didn't work, totally forgot about storing a variable in/by my button instance.
That's exactly what I was looking for as I got different button with different emails.

Thanks again.

keitai
July 20th, 2006, 02:52 PM
hmm found a very strange problem

your code works in a new empty flash file and just


But for an existing flash file (orig. flash 6) I had to do this


function emailTo() {
var address:String;
address = this.address;
getURL("mailto:"+address);
trace (address);
}
footer_mc.mail_btn.address = "test@domain.com";
footer_mc.mail_btn.onRelease = emailTo;


I also noticed when I used function emailTo():Void { I get the error


**Error** Scene=Scene 1, layer=actions, frame=10:Line 1: '{' expected
function emailTo():Void {

**Error** Scene=Scene 1, layer=actions, frame=10:Line 6: Unexpected '}' encountered
}


Any explanation why this occurs???

creatify
July 20th, 2006, 03:18 PM
You're publishing to flash 6? If so thats the case, AS2 isn't supported in flash 6 I believe. The ":Void" - is a form of strict datatyping introduced in AS2. That will def. throw an error when publishing lower than 7.

keitai
July 20th, 2006, 04:53 PM
hmm,

I thought so too, but after reading http://www.kirupa.com/developer/oop2/AS2OOPindex.htm
and especially after reading


ts important to note that ActionScript 2.0 is not necessarily a new language. Rather its a new syntax for implementing an already existing language - the language of ActionScript 1.0. In fact, ActionScript 2.0 gets compiled into ActionScript 1.0 when its added to a published swf file. It will even work in Flash Player 6 (target Flash Player 6.0.65.0 for best optimization).

in the intro (http://www.kirupa.com/developer/oop2/AS2OOPIntro.htm)

So I grabbed a old .fla and now I want to convert the AS to AS 2.0 to optimize and learning purpose. But it must be played with flash player 6.

I also want to do it step by step (as in my example I use _mc instead of :Movieclip).

But now I get second thoughts :(

keitai
July 20th, 2006, 05:10 PM
Oh man, I am stupid.

Turn out I had Publish settings >ActionScript version on ActionScript 1.0
Duh!

Now I have set it to ActionScript 2.0 and Version on Flash player 6.0

Might be usefull for some else

Anogar
July 20th, 2006, 05:26 PM
Heh. :thumb2:

creatify
July 20th, 2006, 08:51 PM
hehe - thats happened to a lot of us in the past