...possible? Anything is possible in Flash. :)
Yes, but it needs to interface with a server application like PHP to handle the data transmit functions. I've got an old PHP email script that I use for everything (Lassie contact form, my portfolio...). It's a reliable old beast (if not a little privative!). Regardless, flash just becomes the deployment vehicle that populates that email script. The only catch is that you need to host the SWF on a PHP enabled server... however, that's not a big deal. Almost every web hosting service is running PHP.
For starters, layout your email form in Flash with dynamic text fields. Also copy the following into a text file and save it as "email.php". This is the email script (it's about 95% code comments). The only lines that you should need to change are the email address and the subject line. Otherwise, you don't have to do anything with this script file but send data to it.
<?php
/***************************************************\
* PHP 4.1.0+ version of email script. For more
* information on the mail() function for PHP, see
* http://www.php.net/manual/en/function.mail.php
\***************************************************/
// First, set up some variables to serve you in
// getting an email. This includes the email this is
// sent to (yours) and what the subject of this email
// should be. It's a good idea to choose your own
// subject instead of allowing the user to. This will
// help prevent spam filters from snatching this email
// out from under your nose when something unusual is put.
$sendTo = "you@youremail.com";
$subject = "Flash site message";
// variables are sent to this PHP page through
// the POST method. $_POST is a global associative array
// of variables passed through this method. From that, we
// can get the values sent to this page from Flash and
// assign them to appropriate variables which can be used
// in the PHP mail() function.
// header information not including sendTo and Subject
// these all go in one variable. First, include From:
$headers = "From: " . $_POST["name"] . "<" . $_POST["email"] .">\r\n";
// next include a replyto
$headers .= "Reply-To: " . $_POST["email"] . "\r\n";
// often email servers won't allow emails to be sent to
// domains other than their own. The return path here will
// often lift that restriction so, for instance, you could send
// email to a hotmail account. (hosting provider settings may vary)
// technically bounced email is supposed to go to the return-path email
$headers .= "Return-path: " . $_POST["email"];
// now we can add the content of the message to a body variable
$message = $_POST["name"] ."\r\n". $_POST["message"];
// once the variables have been defined, they can be included
// in the mail function call which will send you an email
mail($sendTo, $subject, $message, $headers);
?>
Get that set up and make sure your webhost is running PHP. Then I can coach you through the scripting of the Flash form.
This is really quite easy, don't worry!
fatbuoy1- 12-06-2007
...possible? Anything is possible in Flash.
Im sorry I ever doubted... :P
Problem. Turns out my webhost (www.123-reg.co.uk) is about the only one in the world that DOESNT have PHP, can you reccommend a good alternative?
Can you explain the form scripting anyway? Obviously I wont be able to -*test*-('") it but I can still build it can't I?
bigmac- 12-06-2007
Well, what IS your server running? What ever is loaded on the box, just search for a free email script using that server language. All these emails are about the same... they receive POST variables then dispatch them down to the server for processing. They're not very tricky.
As for the Flash end of things, I'll have to look it up in my old website FLA files, which I won't feel like doing these evenings. Work has been bad enough that my computer has been staying OFF. I could check this weekend though. Either way, I know it's running using the AS2 "sendAndLoad" method. As I recall, you grab all the data out of the text fields, add them as nodes on an Object, then fire the object out to the email script. That's psudo-code, but the logic is there.
Tell you what, here's your assignment: look up sendAndLoad in the Flash AS2 dictionary. I'll help you understand what the documentation means. Everything I know about AS I pretty much learned by going through that AS dictionary. I still use it on a daily basis. Bottom line of AS: this stuff isn't rocket science. It's extremely well documented and pretty simple to use if you follow the code examples. The big hurdle is figuring out how to use help and how to understand the documentation. Once that snaps, then you can just start reading the method summaries, understand what they mean, and then you know how to use them. Unfortunately they didn't teach us in school that the magic bullet to programming is the damn Flash help section. They gave us useless code examples that we didn't understand. If they'd just taught us how to understand documentation, half my graduating call would have been writing Lassie engines and stuff =)
fatbuoy1- 12-06-2007
My webhost says something about Perl, ill take a look into it, and that sendAndLoad thing.
Thanks very much for all your help Greg, really appreciate it! I promise in return to never overwork any poor flash developers I work with in my future career ;)
bigmac- 12-06-2007
I wouldn't think it would be Perl that you're after... Perl is some pretty heavy stuff from what (non-existent) knowledge I have of it. I think it's a bit beefier than your standard server application. You don't have PHP, JSP, ASP, .NET, or ColdFusion available? Boy... time to switch servers.
Oh, and I was curious about sendAndLoad so I looked it up really quick (it's been a while). There are two flavors... one for LoadVars and one for XML. You'll want the LoadVars flavor. Post up it's parameters and what is returns, then we'll discuss ;)
bigmac- 12-06-2007
...erm, why are you listed as having been online in the last five minutes? It's almost midnight here, which means it's 5 or 6AM for you, isn't it?
I know you're a student and all, but... go to bed ;)
fatbuoy1- 12-06-2007
Yeh its 4.25am, and i'm trawling the web for tutorials on using Flash with cgi scripting! I've found one i'm going to try, and if it doesn't work i'll go to bed and look at changing web hosts tomorrow! Php does look a LOT simpler... :D
SeanCyrusTowel- 12-07-2007
Pearl was one of the first (I think) cross-platform programming languages. I don't know too much about it, but I know it's old (in computer years, it's like 20,000.... that's, 1000 computer years per earth years, I made it up) It does fall under the GNU General Public Licenese. It was influenced by C/C++, basic, and all those other old programing systems. Not sure how a server would recognize it, BUT it influenced PHP.
Source: http://en.wikipedia.org/wiki/Pearl
fatbuoy1- 12-07-2007
Yeah I spent hours last night trying to work it out, im sure its possible to use Flash and Perl together, but its way more complicated than php, so i'm just changing webhosts (going to www.one.com , anyone got a review of their service?). In the end I just gave up and went to bed, under orders :P
NigeC- 12-07-2007
or try this guy:
http://www.scorpiotaz.net/
I've been with him for over 2 years now, he's been very reliable.. plus very understanding when i abused my bandwidth!
i have php, mysql, frontpage, perl cgi, cpanel etc etc
or if you need some space just to try stuff drop me a pm :wink:
fatbuoy1- 12-07-2007
Apparently i'll be switched over by monday evening so i'll try these ones, but if they turn out bad i'll give your guy a look Nige... is it some guy with a few spare servers in his garage or something?
NigeC- 12-07-2007
Its an American server, so i don't think he has an old Unix server ticking away in his garage lol, i think he bought rack space to do the company site he works for, he's helped me no end over the last year, even upped my bandwidth for free
Web hosting is a dodgy old game, it doesn't take much for a snot nosed kid to build a fancy website to flog off webspace then cut it and run, you can build a Apache server in minutes, i have one for -*test*-('")ing stuff before it goes live.
Some of the deals out there are unreal and you get bugger all for your money, my last domain name was with 123reg i was quite shocked at what you didn't get
fatbuoy1- 12-07-2007
yeh iv bin with them for a year. it was fine but now i need php, n d fact dat dey dont have it is pretty pathetic
bigmac- 12-08-2007
When you're ready with the server, I think this is what you'll need to do in Flash. Mind you, I'm writing this from memory so I can't guarantee the accuracy of this logic:
var com:LoadVars = new LoadVars();
com.email = email_txt.text;
com.subject = subject_txt.text;
com.message = message_txt.text;
com.onLoad = function()
{
feedback_txt.text = "Your message was sent successfully!";
}
com.sendAndLoad("url/of/email.php");
Also note, the property names that you specify on the LoadVars object (email, subject, and message in this example) will need to match what the email script is looking for. The text fields in this example would also need to match up with text fields on the stage.
fatbuoy1- 12-09-2007
Thanks a ton Greg, i'll give that a go tomorrow night when (hopefully) my web page is up and running again. By the way, how would I go about making a movie play backwards when I roll over a button? Iv got a text column that scrolls down (using play() when i rollover the down button) but cant get it to scroll up again...
I was trying to use a tutorial i found that used a controller movie clip that used
_root.prevFrame();
The problem is that I don't want it to reverse the main _root. just a movie clip called txt_scroller (which contains the controller mc and the rewind button... both siblings I think). I changed the script in the controller mc to txt_scroller.prevFrame(); but it doesn't do anything. Have I just not used the right path to the controller mc or is it more complicated than that?
I always have to be awquard dont i? :D
Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.