FORUMS: list search recent posts

Button to send email notification

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Emily Andreas Moynihan
Button to send email notification
on Sep 28, 2012 at 12:31:48 pm

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?


Return to posts index

demetri tashie
Re: Button to send email notification
on Sep 28, 2012 at 2:29:42 pm

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:

submitBTN.addEventListener(MouseEvent.CLICK, sendEMAIL);
function sendEMAIL(e:MouseEvent):void{
var phpURL:URLRequest = new URLRequest("eMail.php");
phpURL.method = URLRequestMethod.POST;
var newLoader:URLLoader = new URLLoader();
newLoader.load(phpURL);
}


and your php file, named 'eMail.php' would look like this:

<?php
$to = "MyEMAIL@MyDOMAIN";

$subject = "from my site";

$message ="This is sent from my site to myself ";

mail($to, $subject, $message);
?>


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


Return to posts index

Emily Andreas Moynihan
Re: Button to send email notification
on Sep 28, 2012 at 3:02:19 pm

That worked perfectly! Thank you for the prompt and helpful response!


Return to posts index


Emily Andreas Moynihan
Re: Button to send email notification
on Sep 28, 2012 at 3:33:43 pm

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?


Return to posts index

demetri tashie
Re: Button to send email notification
on Sep 29, 2012 at 12:54:09 am

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'):

submitBTN.addEventListener(MouseEvent.CLICK, sendEMAIL);
submitBTN2.addEventListener(MouseEvent.CLICK, sendEMAIL);

function sendEMAIL(e:MouseEvent):void{

var myVAR:URLVariables = new URLVariables();
myVAR.buttonMSG = "this is a message from button: "+ e.target.name;


var phpURL:URLRequest = new URLRequest("eMail.php");
phpURL.method = URLRequestMethod.POST;
phpURL.data = myVAR;
var newLoader:URLLoader = new URLLoader();
newLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
newLoader.load(phpURL);
}


adjust the PHP code to read the variable 'buttonMsg' as the message:
<?php
$to = "demtas@mac.com";

$subject = "from my site";

$message = ($_POST['buttonMSG']); // this makes the sent variable the message

mail($to, $subject, $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


Return to posts index

Emily Andreas Moynihan
Re: Button to send email notification
on Sep 29, 2012 at 1:37:58 am

Fantastic! I'll give that a shot!


Return to posts index


Emily Andreas Moynihan
Re: Button to send email notification
on Oct 8, 2012 at 11:47:47 am

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!


Return to posts index

demetri tashie
Re: Button to send email notification
on Oct 10, 2012 at 7:42:10 pm

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:

submitBTN.addEventListener(MouseEvent.CLICK, sendEMAIL);
submitBTN2.addEventListener(MouseEvent.CLICK, sendEMAIL);


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:
var p1:page1 = new page1();
var p2:page2 = new page2();
var redBUTTON:redBTN = new redBTN();
var greenBUTTON:greenBTN = new greenBTN();


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...)

import flash.events.MouseEvent;

var p1:page1 = new page1();
var p2:page2 = new page2();
var redBUTTON:redBTN = new redBTN();
redBUTTON.name = "myRedButton";
var greenBUTTON:greenBTN = new greenBTN();
greenBUTTON.name = "myGreenButton";


contentContainer.addChild(p1);
contentContainer.addChild(redBUTTON);
redBUTTON.x = 60;
redBUTTON.y = 10;


contentContainer.getChildAt(2).addEventListener(MouseEvent.CLICK, traceRED);
function traceRED(e:MouseEvent):void
{
dynText.text = e.target.name;
}
var btnArray:Array = [red_btn,green_btn];

for (var i:uint=0; i<btnArray.length; i++)
{
btnArray[i].addEventListener(MouseEvent.CLICK, bCLICK);
btnArray[i].buttonMode = true;
}

function bCLICK(event:MouseEvent):void
{
dynText.text =" ";
contentContainer.getChildAt(2).removeEventListener(MouseEvent.CLICK, traceRED);
contentContainer.removeChildAt(1);
contentContainer.removeChildAt(1);

switch (event.target)
{
case red_btn :
contentContainer.addChild(p1);
contentContainer.addChild(redBUTTON);
contentContainer.getChildAt(2).addEventListener(MouseEvent.CLICK, traceRED);
break;

case green_btn :
contentContainer.addChild(p2);
contentContainer.addChild(greenBUTTON);
greenBUTTON.x = 60;
greenBUTTON.y = 10;
contentContainer.getChildAt(2).addEventListener(MouseEvent.CLICK, traceRED);
break;
}
}


note the switch/logic statement that removes the old page content movie clip and page button, and adds the correct one:
switch (event.target)
{
case red_btn :
contentContainer.addChild(p1);
contentContainer.addChild(redBUTTON);
contentContainer.getChildAt(2).addEventListener(MouseEvent.CLICK, traceRED);
break;

case green_btn :
contentContainer.addChild(p2);
contentContainer.addChild(greenBUTTON);
greenBUTTON.x = 60;
greenBUTTON.y = 10;
contentContainer.getChildAt(2).addEventListener(MouseEvent.CLICK, traceRED);
break;
}


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.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]