I have this line in my AS3 code. I’m writing a mobile app and this is the last bit where the user clicks a button to load the email program to send a message to us. The below code works on an Android phone. User takes a picture, the pictures is saved to the camera roll, and then the user can click and send us an email with a message and the photo they took. I want to automatically add the last picture taken as an attachment to the email.
Currently I have the below:
var url:String = "mailto:someone@somewhere.com?subject=" + subject + "&body=" + body;
I’ve changed it to something like this, but i keep getting an error (Access of undefined property screenshot" when I use the code below.
var url:String = "mailto:someone@somewhere.com?subject=" + subject + "&body=" + body + "&attachment=" + screenshot;
Probably because that variable doesn’t exist yet until you take a photo. Is there some way to do this? or is there some IF statement i should wrap that line of code in?
The attachment will always be a JPG.
Thanks in advance…
Rob
All you need to do is to have
```actionscript
var screenshot:String;
earlier in your code
hmm ok, I’ll give that a try. If its that easy, that’s amazing.
ok so i tried that, but I’m not getting the attachment attached to the email when i click the button. I’m not getting an error anymore either, so thats good.
I figure i need to tell that var screenshot:String to equal something but i’m not sure of the syntax in that spot.
The other parts like Subject / Body were all text so they were strings. The attachment is an image taken from the camera. And so what i want to do is when the user hits the button it creates a pre-filled email and attaches the last photo taken to the email.
The attachment parameter string would be the local device file path to the image - I think this could well be different per type of phone and don’t think you can access this from within actionscript even if you’re using the latest air for android api
hmm, what if i make the user click a button and select the attachment of the photo or if i write something that puts the files somewhere on the phone so my app will know where they are. Could be tricky.
yeah i actually found a different and probably easier way to do this. Using the StageWebView i can open a webpage that has a basic form on it. I can browse the phone and grab the picture to be emailed. should work…I’m gonna test that out. Thanks for the links. I might give that go if this doesn’t work.
I did notice something else about my app too that i think is odd. I open it up on my phone, i click the button i made in flash to load the camera. When the camera is active and I click the camera button on the phone, it doesn’t do anything. Do i have to write something special in AS3 to tell the phone to allow that button to be used?
is the mailto: with the attachment working for you on the device? It hasnt worked for me, so im wondering if its not supported, or if im doing it wrong.
private function sendEmail(to:String, subject:String, body:String, path:String):void {
var urlString:String = “mailto:”;
urlString += to;
urlString += “?subject=”;
urlString += subject;
urlString += “&body=”;
urlString += body;
urlString += “&attachment=”;
urlString += path;
navigateToURL(new URLRequest(urlString));
}