Copy link to clipboard
Copied
Hi
I'm making a contact form so when you click the submit button it opens up a email window were the subject and message is already fill in because they did it in the contact form. I dont really know which code I should use. I've only gotten this far. The subject and message is textinput and textarea components.
var vEmail:URLRequest = new URLRequest(" mailto:mail@example.com?subject=subjectText&body=bodyText" );
bEmail.addEventListener(MouseEvent.CLICK,fEmailClick);
function fEmailClick(event:MouseEvent):void {
navigateToURL(vEmail," _blank" ) ;
}
use:
var vEmail:URLRequest = new URLRequest(" mailto:mail@example.com?subject="+yoursubjecttextfield.text+"&body="+yourmessagetextfield.text );
bEmail.addEventListener(MouseEvent.CLICK,fEmailClick);
function fEmailClick(event:MouseEvent):void {
navigateToURL(vEmail," _blank" ) ;
}
Copy link to clipboard
Copied
use:
var vEmail:URLRequest = new URLRequest(" mailto:mail@example.com?subject="+yoursubjecttextfield.text+"&body="+yourmessagetextfield.text );
bEmail.addEventListener(MouseEvent.CLICK,fEmailClick);
function fEmailClick(event:MouseEvent):void {
navigateToURL(vEmail," _blank" ) ;
}
Copy link to clipboard
Copied
I didnt work. Still dosent load any subject or message into the email. A stupid question do I have to use import flash.net.URLRequest; or something like that for it to work?
Copy link to clipboard
Copied
First, I would encode the subject and body text using encodeURIComponent:
new URLRequest("mailto:email@domain.com?subject=" + encodeURIComponent(subject) + "&body=" + encodeURIComponent(body));
Secondly, mailto is subject to rather arbitrary and inconsistent limitations across browsers. If the subject or body is too long, for instance, it won't work. In one case where I wanted to provide an error report email feature what I did was copy the text to the clipboard, then simply set the body to "PASTE YOUR CLIPBOARD".
Cheers.
-Aaron
Copy link to clipboard
Copied
okey i tried that code but now i'm getting a error and I dont know how to fix it.
1067: Implicit coercion of a value of type fl.controls:TextInput to an unrelated type String. |
and that code is
new URLRequest("mailto:mail@domain.com?subject=" + encodeURIComponent(subject) + "&body=" + encodeURIComponent(body));
I'm sorry I really dont get this. But I have to do this for a course I'm studying.
Copy link to clipboard
Copied
you should use the code i suggested. if you need to encode your subject/body add ab's suggestion to mine:
var vEmail:URLRequest = new URLRequest(" mailto:mail@example.com?subject="+encodeURIComponent(yoursubjecttextfield.text)+"&body="+encodeURIComponent(yourmessagetextfield.text) );
bEmail.addEventListener(MouseEvent.CLICK,fEmailClick);
function fEmailClick(event:MouseEvent):void {
navigateToURL(vEmail," _blank" ) ;
}
if that fails, make sure your subject textfield is single line.
if that fails, copy and paste the code you're using after adding trace() functions to your code to determine your textfields' text and their length. copy and paste the trace output too.
Copy link to clipboard
Copied
when I put a trace, in the output it shows what i write in the subject and body but when i upload it to the server to check it doesnt load into the mail.
Copy link to clipboard
Copied
What browser? What mail client? Can you post an example trace output?
-Aaron
Copy link to clipboard
Copied
do you have a default emal client? does it open when you click your button to send email?
if yes and yes, did you check the text's length to make sure there wasn't extraneous white space?
Copy link to clipboard
Copied
I figured out the problem and it is that I'm stupid, I put the code outside the button function when I put it in the right place it worked. So thank you both for your help!!
Copy link to clipboard
Copied
but if I can ask a nother question on another thing. I want to make a external textfile load in to a dynamic textfield when I push a button. I searched online but could fine anything that i could understand. I only got this far with code and it doesnt work.
var meddelande:TextField = new TextField();
var textURL:URLRequest = new URLRequest("extern.txt");
var textLoader:URLLoader = new URLLoader();
function knappa3(event:MouseEvent):void
{
textLoader.load(textURL);
meddelande.text = e.target.data;
trace("File loaded successfully.");
}
Del1, Layer 'Layer 2', Frame 1, Line 29 | 1120: Access of undefined property e. |
which is medelande.text = e.target.data;
Copy link to clipboard
Copied
use:
var meddelande:TextField = new TextField();
addChild(meddelande);
var textURL:URLRequest = new URLRequest("extern.txt");
var textLoader:URLLoader = new URLLoader();
textLoader.addEventListener(Event.COMPLETE,loadcompleteF);
// calling knappa3, starts the loading of extern.txt
function knappa3(event:MouseEvent):void{
textLoader.load(textURL);
}
function loadcompleteF(e:Event):void{
meddelande.text = e.target.data; // you can't assign the data until loading is complete
}
Copy link to clipboard
Copied
thank you it works!
Copy link to clipboard
Copied
you're welcome.
Copy link to clipboard
Copied
Ah, my use of "subject" and "body" was shorthand -- they must be strings, wherever you get them from. You can use kglad's syntax to get the text from the TextInput, and wrap in encodeURIComponent like I said. In other words:
new URLRequest("mailto:mail@domain.com?subject=" + encodeURIComponent(mySubjectTextInput.text) + "&body=" + encodeURIComponent(myBodyTextInput.text))
-Aaron