Archive for May, 2010
Simple example – Flash (AS3) and FormMail.cgi
May 29th
I’ve just created a little sample for a friend. He is a designer and “just needed something” that would allow him to capture the data that users enter. FormMail.cgi fits the bill – no need to touch any server files or databases, just point your Flash to a FormMail script that is already installed on your server and off you go – you are sending emails from Flash. It feels bit 90-ies, but it works.
What will you need:
- Flash CS3 or newer (download free 30 days trial from Adobe)
- URL to FormMail.cgi. Many hosting providers have installed FormMail.cgi for you – you will definitely have it if you have cPanel, look under Scripts to find the right path to yours. Otherwise ask your hosting provider or pinch somebody else’s FormMail (not recommended
).
Here are instructions that any Flash designer should be able to follow:
- Create a AS3 Flash document.
- Create your text inputs. My code is using 3 Text Inputs named: messageTI, nameTI, emailTI. You can create more, or rename them, but then you will have to add/modify the code a little bit.
- Create a button and name it sendB
- Create a dynamic text and name it statusTF
- Create an Actions layer and in the first frame put the following code, than modify the FormMail URL and recipient’s email:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | import flash.events.MouseEvent; import flash.profiler.showRedrawRegions; import flash.net.URLRequest; import flash.net.URLRequestMethod; sendB.addEventListener(MouseEvent.CLICK, sendData); function sendData(e:MouseEvent):void { if (messageTI.text.length > 3 && nameTI.text.length > 3 && emailTI.text.indexOf("@") > -1) { //very, very basic data validation (as this is not a data validation tutorial) var r:URLRequest = new URLRequest("http://YOUR-URL-TO-FORM-MAIL/FormMail.cgi"); //modify this URL var v:URLVariables = new URLVariables(); v.recipient = "YOUR-EMAIL@DOMAIN.com"; //put your email here v.subject = "My FormMail test"; //this will be the subject of the email v.email = emailTI.text; v.realname = nameTI.text; //user's name will be appended to his/hers email to form a From field of the email. v.theMessage = messageTI.text; //theMessage is a custom key. If you need more Input fields, just make up more custom fields like this one r.data = v; r.method = URLRequestMethod.POST; var loader:URLLoader = new URLLoader(); loader.addEventListener(Event.COMPLETE, completeHandler); try { loader.load(r); } catch (error:Error) { statusTF.text = "Unable to send data."; //we could definitely do more in terms of error handling, however this is not a error handling tutorial } } else { statusTF.text = "Please enter all required information."; } } function completeHandler(event:Event):void { statusTF.text = "Data submitted."; var loader:URLLoader = URLLoader(event.target); trace("completeHandler: " + loader.data); } |
Notes:
- You can place your components (Button, TextInputs & Dynamic Text) anywhere you like on a page, style them anyhow you like, but make sure they are in the first frame and have the correct names (case sensitive).
- If email is getting send but you are not receiving any – check your spam folder.
- You are too lazy to copy/paste? I hear you. Here is the sample flash file.
Flex SDK bug: The first color in ColorPicker (black) cannot be selected
May 21st
Ha, I found a bug in the SDK! (Well, OK, I didn’t find it, one of the testers did
. Let’s be very nice; let’s put it in Adobe’s Bug System, describe it and suggest a workaround
.
Dodgy Mini DisplayPort to DVI adapter
May 13th
You get such great deals on Ebay, or do you? Like this adapter from Hong Kong for less then $10 incl. postage when a new original Apple one is $45. Well, it did work great for 3 months and then, one day, the MacBook just showed me a little disco – the display was flashing in rapid succession; somehow the switch sequence to external display was failing and it kept on trying… after a while it stopped trying. So, I dished out $45 for an original Apple adapter today and was relieved that it was indeed only an adapter issue and not a broken port on the notebook.
Still, I do consider $45 for this little adapter to be an epic rip off; that’s like you get 8 adapters for same money as a little netbook. Hmmmmm.
ADL doesn’t open the Air application
May 9th
So, you are writing an Air app (or more likely just imported one from somewhere), you try to debug it and the AIR Debug Launcher (ADL) just sits in the Dock (on Mac) and doesn’t open any window, doesn’t throw an error, nothing. Well, you will want to check that you are not using a Flex application class but rather the Air application class; i.e. <s:WindowedApplication>. Duh
Codewars disaster
May 6th
I’ve just failed my poor teammate at Webdu Codewars. So sorryyyy!
Anyway, rather than write a million excuses, here is what it was supposed to look it like after that 20 minutes of coding.
(The original task was to code, in 20 minutes, an “App that would make Steve Jobs relax” or something along those lines).
Please note that the link above is rated QR. It contains some violence and silly jokes and is not really recommended for any audiences.
More of Apple vs. Adobe…
May 2nd
New wave of articles has been sparked after by Jobs’ Thoughts on Flash – Ars published an IMHO bit lame comentary by a guy from Free Software Foundation; there is an interesting prophecy about the world 5 years from now by Charlie Stross… well and here are a few words from none other than my humble self:
Competition is good. HTML5 might be the uber great way of the future – but competition can only make it better. For example on Android phones, HTML5, Flash and native SDK pimp themselves to developers – and I trust the devs will pick the hottest one for their project. They will be forever comparing and throwing simple but rock solid complaints at the SDK makers – “Why SDK ‘A’ can do ‘X’ so well but you can’t?”.
I can promise that I’ll be very quick to give up on mobile Flash if it failed to prove itself against other solutions; but as well I’ll be quick to defend Flash if deserved. Interesting times lie ahead.
