Button to send email notification
I am working on a Flash site and have a button on the homepage. I would like to set it up so that anytime someone clicks on that button, I get an email to my inbox saying that someone has clicked on it. I have tried modifying Flash/php forms (removing all the input boxes and updating code) to capture just the email notification element, but so far this is not working. Is there a simple way to do this?
first make sure your server is set up for PHP scripts.
then, in its most basic form, for a button named "submitBTN" , your actionscript could look like this:
and your php file, named 'eMail.php' would look like this:
obviously change the $to variable to reflect your email that you want it sent to, the $subject variable to be whatever subject you want shown, and the $message variable to the message you want received
i hope that helps
That worked perfectly! Thank you for the prompt and helpful response!
As a follow up, what would be the best way to make $message a variable so that I could create only one php file but put several buttons throughout the site that would email me different messages depending on the button?
to do that ( utilizing the same PHP file and code, but for different buttons to send a different message)
you could use/pass a variable to stand in for and differntiate the message. this variable could contain the name of the button clicked to let you kow specifically which button the message is sent from.
coded like this, you can have as many buttons as you want, and the message will tell you which button was clicked, by telling you the name of the button ( the 'e.target.name'):
adjust the PHP code to read the variable 'buttonMsg' as the message:
the actual variable being sent and read in the PHP is ' buttonMSG'
this to me would be the easiest and most succint way of handling that
Fantastic! I'll give that a shot!
This worked great! So now I have hopefully one final question. These buttons are spread throughout my website and already have functions attached to them. Is there a way to set up this email function once and have the button functions call it without having to copy all of this code into every button function. (i.e. is there a way to add a single line of code to each button that references this function?) Thank you so much for all your help!
this coded isn't added into the buttons, it is placed on the timeline. you now have me nervous tha you are placing code inside a button/movieclip's timeline. if that is so, that is not what i ever meant to imply.
ideally, you would not work with more than a 1 frame timeline, with all the code therefore just in one place.
the code is also written - as is - so that there is just one function. all the buttons reference the same function 'sendEMAIL'. it is just that every button that you want to use that function needs an EventListener attached to it, like this:
the question, and problem, comes, when you are spreading out elements ( buttons in this case) across a timeline. code, once delcared ( say for example in the first frame) must have any element mentioned in the code available to it at that moment. code can not 'see into the future' or know of the existence of an element in a 'future' frame.
therefore, most flash built sites ( if people are still doing full flash built navigation...) no longer rely on a timeline / linear navigation style.
as a transition into this 'newer' way of creating navigable sites, people strove to put all the code of the project in the first frame ( which extended over the length of the entire timeline) and then manipulate elements properties - ( usually their alpha or visisble properties) to make them appear and disappear at the appropriate place and time, when in actuality, they are already 'declared' and 'alive' in the first frame, just not 'visible'. another way was to utilize Library assets and have them added or removed as needed
logical statments were employed to be able to do this, to turn on/off visibility,or to add elements from the Libray, or even external elements, based on certain conditions ( for example: 'IF this is frame label 'GALLERY', let the gallery button and 'modul'e be visible, and all other buttons and 'modules' not be visible)
a better way is to eliminate the timeline and bothersome navigation of it. you can set up your project to have a 1 frame main timeline, and all your code can be on this first frame.
your project, reconfigured this way, would have your main navigation buttons call a function which will load in both the 'page' content, as well as the button(s) that trigger the PHP
if you create your 'page' sections, convert them to MovieClips, and set their properties to Export for Actionscript with a Class/Linkage name, then they are available to be added, and removed, from/to the Library.
likewise for your page section buttons that trigger the PHP ( NOTE: every time i say 'button', i mean a MovieClip symbol that will act as a button)
in the example below, i have 2 main navigation buttons, one with the instance name 'red_btn' and the other 'green_btn'.
see examaple here
there is a yellow rectange movieclip to act as they main content area container. this has an instance name of 'contentContainer'. the separate 'pages' will be added as Children, from the Library, to this movieclip container.
so in the Library is a MovieClip named 'page 1' with an Export/Linkage class name of 'page1' Likewise a 'page 2' with Linkage class name 'page2'. also 2 movieclips: 'greenButton' and 'redButton' with linkage names 'greenBTN' and redBTN'
as long as they are all declared in the code, they can be added and removed at will:
here is the complete code that makes this work ( note: this example was made quickly. it WILL work, but i am not swearing the coding is the best...)
note the switch/logic statement that removes the old page content movie clip and page button, and adds the correct one:
i am sure that is lot to take in, as it is a different way of conceptualizing your site, but it will help move you closer to working in a true OOP manner.
i hope that helps.