PHP to Flash / Functions
I want to perform an action in Flash, so it sends values to
PHP
[Code]
SendTheData = function(type,val,other){
SendData = new LoadVars();
SendData.type = val;
SendData.varName = other;
myData.send("
http://www.url.com/page.php",
SendData, "POST");
Is this the correct way? I may have got it all wrong to start
to be honest.
[/code]
If I then call SendTheData(name,jim,20)
I want "SendData.type = val" to pick up the 'type' value sent
to the function and send so I can receive in PHP using
$_POST['name'] - I think how I have done it it would receive
$_POST['type']
SendData.varName = other;//but I want this to receive
$_POST['varName'] = which I think is correct
Any ideas?
Use the LoadVars Object for Send or SendAndLoad function..
Below is the correction
Similar Messages
-
Hi all,
this is my first post I'm a newbee teaching myself, so i hope
I'm Clear
I have No problems inserting data from flash to PHP into
MySQL,
it's sendind them back properlly.
All I'd like to see happen is for one row of data to be
inserted into a dynamic text field.
here's what i've got
if i access this php file, it prints out a vertical list from
a single MySQL row,
I was happy.
$query = "select row from table";
$result = mysql_query($query, $db);
while($row = mysql_fetch_row($result))
print "$row[0]<BR>\n";
From flash :
I created a dynamic text field w/ an instance, my_to.
var lv:LoadVars = new LoadVars();
lv.load ("data.php");
lv.onLoad = function(){
my_to.text = lv;
and Instead of the vertical list (which i would love to see)
i get an unparsed data array.
I can't imagine i'm to far off,
what am I missing?
I hope not alot
AlexYou should use amfphp. It's flash remoting with php. It's
much cleaner integration.
http://www.amfphp.org
Otherwise, to use loadvars, you have to export your data from
php like this: "name1=$row[0]&name2=$row[1]..."
then in flash use: lv.name1 will equal $row[0] -
Can't get PHP's mail() function to work on local Apache install
I'm using Leopard and installed all available updates. I've done a clean install of Leopard, so no Tiger upgrade.
I've installed the latest stable versions of Apache, PHP and MySql through MacPorts/command line in Leopard. So far so good, everything works except for PHP's mail() function.
Does anyone know how to get PHP's mail() function to work on my localhost? Searching the web through Google taught me it's impossible to get it to work under Leopard but I find that hard to believe. Can anyone help me out?Any help appreciated.
-
Calling Flash function from IE10
Hey guys,
So I am attempting to have some javascript call a flash function. I have it fully working with older versions of IE, such as IE9. However IE10 will not do it.
I followed the example provided by Adobe here: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/External Interface.html#addCallback()
Using this example code, (in IE10) I am successfully able to send data from flash to my Javascript, but coming from the other direction, it does not work.
The error I get is ("Object doesn't support property or Method 'methodNameHere' ")
Does anyone have any ideas of what I might need to do? Or does IE10 not support that communication any longer? Any thoughts are appreciated, thanks!The code is that which is in the link but I will post it here below. Here is what I am doing in my flash file:
sendBtn.addEventListener(MouseEvent.CLICK, clickHandler);
if (ExternalInterface.available) {
try {
output.appendText("Adding callback...\n");
ExternalInterface.addCallback("sendToActionScript", receivedFromJavaScript);
if (checkJavaScriptReady()) {
output.appendText("JavaScript is ready.\n");
} else {
output.appendText("JavaScript is not ready, creating timer.\n");
var readyTimer:Timer = new Timer(100, 0);
readyTimer.addEventListener(TimerEvent.TIMER, timerHandler);
readyTimer.start();
} catch (error:SecurityError) {
output.appendText("A SecurityError occurred: " + error.message + "\n");
} catch (error:Error) {
output.appendText("An Error occurred: " + error.message + "\n");
} else {
output.appendText("External interface is not available for this container.");
function receivedFromJavaScript(value:String):void {
output.appendText("JavaScript says: " + value + "\n");
function checkJavaScriptReady():Boolean {
var isReady:Boolean = ExternalInterface.call("isReady");
return isReady;
function timerHandler(event:TimerEvent):void {
output.appendText("Checking JavaScript status...\n");
var isReady:Boolean = checkJavaScriptReady();
if (isReady) {
output.appendText("JavaScript is ready.\n");
Timer(event.target).stop();
function clickHandler(event:MouseEvent):void {
if (ExternalInterface.available) {
ExternalInterface.call("sendToJavaScript", input.text);
And here is exactly what is in the HTML:
<!-- saved from url=(0014)about:internet -->
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ExternalInterfaceExample</title>
<script language="JavaScript">
var jsReady = false;
function isReady() {
return jsReady;
function pageInit() {
jsReady = true;
document.forms["form1"].output.value += "\n" + "JavaScript is ready.\n";
function thisMovie(movieName) {
if (navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName];
} else {
return document[movieName];
function sendToActionScript(value) {
thisMovie("ExternalInterfaceExample").sendToActionScript(value);
function sendToJavaScript(value) {
document.forms["form1"].output.value += "ActionScript says: " + value + "\n";
</script>
</head>
<body onload="pageInit();">
<form name="form1" onsubmit="return false;">
<input type="text" name="input" value="" />
<input type="button" value="Send" onclick="sendToActionScript(this.form.input.value);" /><br />
<textarea cols="60" rows="20" name="output" readonly="true">Initializing...</textarea>
</form>
</body>
</html> -
Ebook of tutorial - PHP 5 & Flash cs4
im looking for a descent book or tutorial wich will teach me how to put php in flash cs4
i got a book here at school, but its for AS 2.0 ...
no point in reading that one ..
thx in advance
grtzzzzzzHere are some basic tuts for the same :-
http://www.flashconf.com/actionscript/how-to-mail-flash-form-with-actionscript/
http://video-tutorial.eu/free-video-tutorial/web-design/flashvars-and-php-tutorial-send-dy namic-variable-into-flash.html -
How call Flash function from C++?
Communication between C++ and ActiveX Flash object is
adjusted. The ActiveX calls C++ functions. But how a call Flash
functions from C++?
I try so: v_flash is control variable of the ActiveX the
container.
A code: v_flash. CallFunction ("test");
No effect
How it to make?Hi David, Thanks for the response. I found this solution by
following method:
Flash code either in class or frame:
ExternalInterface.addCallback("sendTextToFlash",
getTextFromJavaScript);
public function getTextFromJavaScript(user):void {
trace(user);
//Now whenever JavaScript function will be called from any
HTML or back end language then it definetly call directly that
flash function by following method
//HTML Code
function sendData(user){
//alert("values coming "+user);
SendDataToFlashMovie(user);
function getFlashMovieObject(movieName){
if (window.document[movieName]){
return window.document[movieName];
if (navigator.appName.indexOf("Microsoft Internet")==-1){
if (document.embeds && document.embeds[movieName])
return document.embeds[movieName];
else {// if (navigator.appName.indexOf("Microsoft
Internet")!=-1) {
return document.getElementById(movieName);
function SendDataToFlashMovie(user) {
var flashMovie=getFlashMovieObject("myFLA");
flashMovie.sendTextToFlash(user);
Now HTML or back end language has just need to call
sendData(
value)
I think its the right way, but if there is any other short
method like just call the function name from HTML and that directly
respond to Flash as per function name, then please let me
know. -
Mysql- PHP- FLASH function. (Passing function to a package)
I've just started with ActionScript3.0, and is currently
working on a flash that is to communicate with a mysql database and
have found a great deal of example code online that I've started to
work with.
Currently I have the following package added to my project:
quote:
package
import flash.events.*;
import flash.net.*;
public class SendAndLoad
public function SendAndLoad()
public function sendData( url:String, _vars:URLVariables,
completeFunc:Function ):void
var request:URLRequest = new URLRequest( url );
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
request.data = _vars;
request.method = URLRequestMethod.POST;
loader.addEventListener( Event.COMPLETE, completeFunc );
loader.addEventListener( IOErrorEvent.IO_ERROR, onIOError );
loader.load(request);
//private function handleComplete( event:Event ):void
// var loader:URLLoader = URLLoader( event.target );
// trace( "Par: " + loader.data.par );
// trace( "Message: " + loader.data.msg );
private function onIOError(event:IOErrorEvent):void
trace("Error loading URL.");
And is running the following code in my flash:
quote:
import SendAndLoad;
import flash.net.URLVariables;
function loadUsername( event:Event ):void
var loader:URLLoader = URLLoader( event.target );
//userNameText.text = "ffff";
userNameText.text = loader.data.user;
var url:String = "pages/test.php";
var vars:URLVariables = new URLVariables();
var sal:SendAndLoad = new SendAndLoad();
sal.sendData( url, vars, loadUsername );
As you can see I am trying to seperate the function to be
called when the return value of the page I am accessing returns
with a value, so I wont need to pass all different actions to be
called on different pages I will be requesting throughout my flash
program.
But as it is now, the function loadUsername, never even gets
called, which I assume is because the package can't call the
function outside it.
As I said, I am just starting out with ActionScript 3.0, and
is kind of stuck at this.
Any thoughts?I never tried to pass a function into a class an attempt to
execute it. I am not sure this approach will ever work.
I suggest the following approach (see code): -
Sending variable value from php to flash to load an xml file
I would like to load an XML file from the location locally or on the server being unaware of the name of the file. I am using PHP for sending the filename to Flash.
The below is the PHP code:
<?php
filesInDir('C:\Documents and Settings\457305\My Documents\shrikant\Flash Tutorials\webassist');
function filesInDir($tdir)
$dirs = scandir($tdir);
foreach($dirs as $file)
if (($file == '.')||($file == '..'))
elseif (is_dir($tdir.'/'.$file))
filesInDir($tdir.'/'.$file);
else
echo "fileName=$file";
?>
And below is the loading Actionscript code:
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.net.URLVariables;
stop();
// Define the PHP file to be loaded
var phpFile:String = "http://localhost/webassist/test.php";
var cons_xml:XML;
var xmlLoader:URLLoader = new URLLoader();
// Specify dataFormat property of the URLLoader to be "VARIABLES"
// This ensures variables loaded into Flash with same variable names
xmlLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
xmlLoader.load(new URLRequest(phpFile));
xmlLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(evt:Event):void
trace(evt.target.data.fileName);
//cons_xml = new XML(evt.target.data.fileName);
//gotoAndPlay(2);
When I trace the evt.target.data it displays "fileName=mainOpenEndedXML%2Exml" and when I trace evt.target.data.fileName the fileName is properly displayed as "mainOpenEndedXML.xml".
But in the next two lines where the loading occurs it does not load the file i.e the swf file from xml doesn't play.
I have been searching the Internet for answers but not able to find any solutions.
The loading works properly if i directly insert the xml file in the code and the swf's in the XML file play propertly. The below is the code for the same:
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.net.URLVariables;
stop();
var cons_xml:XML;
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest("mainOpenEndedXML.xml"));
xmlLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(evt:Event):void
cons_xml = new XML(evt.target.data);
gotoAndPlay(2);
Any help on this would be greatly appreciatedYes. you already said that, but I guess you don't understand what I said. You are loading the PHP fle to get the filename, but nowhere are you taking that filename and loading the file that was named.
You need to do two loading operations. The first one to get the filename, and the second to load the file with that name. Maybe if you name the PHP file loader phpLoader instead of xmlLoader it will start to make more sense to you. Something like the following...
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.net.URLVariables;
stop();
// Define the PHP file to be loaded
var phpFile:String = "http://localhost/webassist/test.php";
var phpLoader:URLLoader = new URLLoader();
// Specify dataFormat property of the URLLoader to be "VARIABLES"
// This ensures variables loaded into Flash with same variable names
phpLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
phpLoader.load(new URLRequest(phpFile));
phpLoader.addEventListener(Event.COMPLETE, processPHP);
function processPHP(evt:Event):void
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest(String(evt.target.data.fileName)));
xmlLoader.addEventListener(Event.COMPLETE, processXML);
var cons_xml:XML;
function processXML(evt:Event):void
cons_xml = new XML(evt.target.data);
gotoAndPlay(2); -
XML, PHP and Flash forms
After searching several tutorials and forum posts, I still am
puzzled at how to get started on this.
I want to enable my client to upload changes to the XML file
used on his site without knowing anything about XML. He also wants
to upload images which are referenced in the XML. So, I am assuming
that I create a form that allows him to type in changes to sections
and select an image on his local drive and submit it to a PHP
script on the server which will, in turn generate/update the XML
and upload the image(s).
Is this correct or am I going about it the wrong way? Of
course, I should just tell him he'll have to pay me to update the
site. ;-) I'm really confused about how to start this whole thing
in the planning stage. I just need a little direction then I can
research the rest.
thanks!aniebel wrote:
> So, do I make fields (variables) for each node in the
XML? And can I use any
> PHP script that converts my loadvars to XML? I'm not
sure what to search for,
> specifically. I hope I'm not in over my head but it
seems getting into these
> predicaments is a great way to learn.
>
are you making this admin interface in flash then? personally
I would
steer clear of that as it will be harder to debug - doing it
in HTML
will be much more straightforward, and if you do it right you
can change
to using a flash front end in future.
Handling file uploads in PHP is a little tricky but there are
loads of
good pages of advice on using PHP on the web. Here's a good
place to
start as there's lots of notes by other users:
http://us2.php.net/manual/en/function.is-uploaded-file.php
XML with PHP I have only done once - and I think that was
just reading
it and not writing it. Should be OK though, again, lots of
help
available online!
MOLOKO
Macromedia Certified Flash MX 2004 Developer
Macromedia Certified Flash MX Developer
::remove _underwear_ to reply::
'There ain't no devil - it's just God when he's drunk' Tom
Waits
GCM/CS/IT/MC d-- S++:- a- C++ U--- P+ L++ !E W+++$ N++ O? K+
w+++$ !O M+
VMS? PS+++ PE- Y PGP+ t+ 5-- X-- R* tv++ b++++ DI++++ D+ G e
h-- r+ y++ -
Passing variable from php into flash, help please
Here are what I'm having:
<?PHP
$testVal = "This is a test";
$test = urlencode($testVal);
$out = "test=". $testVal;
echo $out;
?>
// and this is my flash file
function getData() {
// Prepare request
var urlReq:URLRequest=new URLRequest("http://localhost/test.php");
urlReq.method=URLRequestMethod.GET;
var loader:URLLoader = new URLLoader();
loader.dataFormat=URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, completeHandler);
loader.load(urlReq);
function completeHandler(evt:Event) {
var vars:URLVariables = URLVariables(evt.target.data);
trace(" TEST = ", vars.test);
trace(" TEST = ", unescape(vars.toString()));
// and below is the ouput
TEST = undefined
TEST = test=This is a test
I've tried with several different ways to get ONLY the value of the variable - that means I only want to have "This is a test" returned, but I either got "undefined" or the whole thing "test=This is a test", instead.
I'm new to Flash and PHP. Please help.
ThanksThere's no need to write any fake variables out, Flash does not need that. OK, here's a simple PHP script like yours - I called it test.php
<?PHP
$testVal = "This is a test";
$out = "test=". $testVal;
echo $out;
?>
And the AS to call it:
var myLoader:URLLoader = new URLLoader();
myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
myLoader.load(new URLRequest("http://www.mydomain.com/test.php"));
myLoader.addEventListener(Event.COMPLETE, dataLoaded, false, 0, true);
function dataLoaded(e:Event){
trace( e.target.data.test);
You will see 'This is a test' traced to the output window.
HTH -
I have a dynamic text instance in Flash named dynamic_txt and
I want it to display information from a php file. What command
allows me to do this? Here is the code:
PHP
<?php
print "dynamo_txt=DYNAMIC";
?>
ActionScript (2.0)
var my_lv:LoadVars = new LoadVars();
my_lv.onLoad = function(success:Boolean) {
if (success) {
//HERE IS WHERE I WANT THE COMMAND THAT WILL ALLOW DYNAMO_TXT
TO DISPLAY THE STRING //FROM THE PHP FILE
my_lv.load("cars.php");Read my threads - you use LoadVars and put value-pairs into
an array.
Unfortunately, it was answered in AS 1.0/2.0 forum, not here
so perhaps you didn't find it.
//sqlcache
/* fyi you can always create some valid test data locally by
doing something like this:
var mytest:LoadVars=new LoadVars();
mytest.keyword10="keyword1"
mytest.keyword11="organelle"
mytest.keyword12="photosynthesis"
mytest.keyword13="digestion"
mytest.keyword14=""
mytest.keyword15=""
trace(mytest.toString())
var my_lv:LoadVars = new LoadVars();
my_lv.onLoad = function (success:Boolean):Void {
if (success) {
//assuming _global.keywords is already defined as an array:
//assuming _global.keywords might already have some keywords
in it (otherwise this could be simpler)
//create a temporary array:
var tmpkeywords:Array =[];
// Iterate over properties in my_lv
for (var prop in my_lv) {
if (typeof(my_lv[prop])=="string"){
tmpkeywords.push(my_lv[prop]);
trace("loaded in this order:"+tmpkeywords); //it is reversed,
so:
tmpkeywords.reverse(); //turn it around
trace("reversed:"+tmpkeywords);
//now assuming that the _global.keywords is already an array
with some words... and we want to
//add to the end:
//the following 'function.apply' method lets the 'push'
method take the elements of tempwords as an array an adds them
individually
_global.keywords.push.apply(_global.keywords,tmpkeywords);
trace("global keywords now has:"+_global.keywords)
} else {
trace("Unable to load external file.");
//make _global.keywords an array for testing:
_global.keywords=["hello","world"];
trace("global keywords starts with:"+_global.keywords)
my_lv.load("sqlcache.txt");
//sqlcache.txt
GWD
User is offline
View Profile
Senior Member Posts: 1927
Joined: 06/24/2002
Send Private Message
03/11/2008 05:30:13 AM
Reply | Quote | Top | Bottom
You wouldn't usually want to or need to load the same data in
twice.
I checked the link to your swf and I couldn't see it
attempting to load any external data via http activity. So I don't
think this code is running in your full swf (or perhaps it's only
after signing in etc?)
Also, LoadVars automatically calls its own decode method by
default, so you do not need to use 'decode' in the onLoad handler.
Here's something which might help. Hopefully the comments
etc, explain a little bit. The function.apply line is probably the
one that might be a little difficult to comprehend. Its only there
as a quick way to append the values to the _global.keywords array
(assuming that you want append them). -
Pull images from SQL/PHP into Flash
I have a website that displays images that are stored in a
SQL database using PHP as a method for pulling and displaying the
images. These images are stored in the database as text (ex:
image1), then the PHP looks for the image like this:
<img src="images/Photograph/<?php echo
$row_rs_Photos['Image']; ?>.jpg" alt="" width="<?php echo
$row_rs_Photos['Thumb_Width']; ?>" height="<?php echo
$row_rs_Photos['Thumb_Height']; ?>" border="0" title="" />
I want to pull these images into Flash. I've done a bunch of
ActionScripting, but am no expert. Really don't have the foggiest
idea where to start.
-kirkI seem to have this one working, kinda. It has an array and
automatically numbers the buttons, but there are some buttons, that
ask SQL to return a photo that doesn't exist. For instance, there
is no 7 or 8 ID in my SQL, so those buttons don't work:
http://www.lbiphotos.com/Flash/loadImages_finished.html
PHP Code:
<?php require_once('my.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType,
$theDefinedValue = "", $theNotDefinedValue = "")
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue)
: $theValue;
$theValue = function_exists("mysql_real_escape_string") ?
mysql_real_escape_string($theValue) :
mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" :
"NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) .
"'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" :
"NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue :
$theNotDefinedValue;
break;
return $theValue;
$colname_rs_Photos = "-1";
if (isset($_GET['passID'])) {
$colname_rs_Photos = (get_magic_quotes_gpc()) ?
$_GET['passID'] : addslashes($_GET['passID']);
mysql_select_db($database_LBI_Photos_Connection,
$LBI_Photos_Connection);
$query_rs_Photos = sprintf("SELECT ID_Photos, Image,
YearPhotographed FROM Photos WHERE ID_Photos = %s",
GetSQLValueString($colname_rs_Photos, "int"));
$rs_Photos = mysql_query($query_rs_Photos,
$LBI_Photos_Connection) or die(mysql_error());
$row_rs_Photos = mysql_fetch_assoc($rs_Photos);
$totalRows_rs_Photos = mysql_num_rows($rs_Photos);
$imageId = $_GET['passID'];
//MUST use code below to grab $images
$images =
$row_rs_Photos['YearPhotographed'].'/'.$row_rs_Photos['Image'];
print "image=" . $images;
?>
<?php
mysql_free_result($rs_Photos);
?>
ACTIONSCRIPT:
function loadImage(passID:Number) {
var resultLv:LoadVars = new LoadVars();
var sendLv:LoadVars = new LoadVars();
resultLv.onLoad = function(success) {
if (success) {
mcLoader.loadClip(imagePath+this.image+".jpg",
loadContainer);
trace("passID: "+passID);
sendLv.sendAndLoad(phpPath+"?passID="+String(passID),
resultLv);
function loadInit(target:MovieClip) {
trace("Begin Loading File");
trace("imagePath + this.image ; "+imagePath+this.image);
function assignButtons() {
for (var i in loadButtons) {
this[loadButtons
].numberTxt.text = String(Number(i)+1);
this[loadButtons].onRollOver = function() {
this.gotoAndStop(2);
this[loadButtons
].onRollOut = function() {
this.gotoAndStop(1);
this[loadButtons].onRelease = function() {
trace("String(this).length "+String(this).length);
if (String(this).length == 16) {
loadImage(Number(String(this).substring(String(this).length-1)));
if (String(this).length == 17) {
loadImage(Number(String(this).substring(String(this).length-2)));
var loadButtons:Array = new Array('loadBtn1', 'loadBtn2',
'loadBtn3', 'loadBtn4', 'loadBtn5', 'loadBtn6', 'loadBtn7',
'loadBtn8', 'loadBtn9', 'loadBtn10', 'loadBtn11', 'loadBtn12',
'loadBtn13', 'loadBtn14', 'loadBtn15', 'loadBtn16');
var loadContainer:MovieClip =
this.createEmptyMovieClip("loadContainer",
this.getNextHighestDepth());
var siteUrl:String = "
http://www.lbiphotos.com";
var imagePath:String = siteUrl+"/images/Photograph/";
var phpPath:String = siteUrl+"/Flash/images.php";
var mcLoader:MovieClipLoader = new MovieClipLoader();
var mcLoadObj:Object = new Object();
mcLoadObj.onLoadInit = loadInit;
mcLoader.addListener(mcLoadObj);
//below centers called image
loadContainer._x = (Stage.width/2-100);
loadContainer._y = (Stage.height/2-100);
assignButtons(); -
Passing variables from PHP to Flash
I have a contact form that works. The user enters their info,
hits submit, and their info is emailed to me. I need to figure out
how to have the PHP script send back a confirmation that the email
was actually sent. I can't get the php to echo just a "yes" or
"no". Here is what I have so far:
Flash code to bring in PHP variable to notify user if mail
has been sent or not:
function receive_response(e:Event):void
var loader:URLLoader = URLLoader(e.target);
var email_status = new URLVariables(loader.data).success;
if(email_status == "yes")
status_txt.text = "Success! Your message was sent.";
timer = new Timer(500);
timer.addEventListener(TimerEvent.TIMER, on_timer);
timer.start();
else
status_txt.text = "Send failed! Please email or call us";
and here is my entire PHP Code. The code in bold at the bottom
is where it is supposed to pass the "yes" or "no" as the variable
success
<<meta http-equiv="content-type"
content="text/html;charset=utf-8">
<?php
// Create local PHP variables from the info the user gave in
the Flash form
$senderName = $_POST['userName'];
$senderEmail = $_POST['userEmail'];
$senderMessage = $_POST['userMsg'];
// Strip slashes on the Local variables
$senderName = stripslashes($senderName);
$senderEmail = stripslashes($senderEmail);
$senderMessage = stripslashes($senderMessage);
$to = "info@*******.com";
// change this to reflect your site
$from = "contact@*********.com";
$subject = "Contact from ***********.com";
//Begin HTML Email Message
$message = <<<EOF
<html>
<body bgcolor="#FFFFFF">
<b>Name</b> = $senderName<br /><br />
<b>Email</b> = <a
href="mailto:$senderEmail">$senderEmail</a><br
/><br />
<b>Message</b> = $senderMessage<br />
</body>
</html>
EOF;
//end of message
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
$to = "$to";
if (mail($to, $subject, $message, $headers))
echo “success=yes”;
else
echo “success=no”;
exit();
?>
ThanksI have a contact form that works. The user enters their info,
hits submit, and their info is emailed to me. I need to figure out
how to have the PHP script send back a confirmation that the email
was actually sent. I can't get the php to echo just a "yes" or
"no". Here is what I have so far:
Flash code to bring in PHP variable to notify user if mail
has been sent or not:
function receive_response(e:Event):void
var loader:URLLoader = URLLoader(e.target);
var email_status = new URLVariables(loader.data).success;
if(email_status == "yes")
status_txt.text = "Success! Your message was sent.";
timer = new Timer(500);
timer.addEventListener(TimerEvent.TIMER, on_timer);
timer.start();
else
status_txt.text = "Send failed! Please email or call us";
and here is my entire PHP Code. The code in bold at the bottom
is where it is supposed to pass the "yes" or "no" as the variable
success
<<meta http-equiv="content-type"
content="text/html;charset=utf-8">
<?php
// Create local PHP variables from the info the user gave in
the Flash form
$senderName = $_POST['userName'];
$senderEmail = $_POST['userEmail'];
$senderMessage = $_POST['userMsg'];
// Strip slashes on the Local variables
$senderName = stripslashes($senderName);
$senderEmail = stripslashes($senderEmail);
$senderMessage = stripslashes($senderMessage);
$to = "info@*******.com";
// change this to reflect your site
$from = "contact@*********.com";
$subject = "Contact from ***********.com";
//Begin HTML Email Message
$message = <<<EOF
<html>
<body bgcolor="#FFFFFF">
<b>Name</b> = $senderName<br /><br />
<b>Email</b> = <a
href="mailto:$senderEmail">$senderEmail</a><br
/><br />
<b>Message</b> = $senderMessage<br />
</body>
</html>
EOF;
//end of message
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
$to = "$to";
if (mail($to, $subject, $message, $headers))
echo “success=yes”;
else
echo “success=no”;
exit();
?>
Thanks -
Passing variables from php to flash and the opposite
Hi guys, im trying weeks now to solve this problem but nothing yet
If someone could just tell me how to pass variables from flash to php and the opposite i would be thankful!!! Please help!I have recently had to learn this, so this may not be the best way but it worked for me
I suggest looking at the code below stripping out everything you don't need (e.g. the databse stuff) and just get a simple string going back and forward
have a go and post any problems here and I'll try and help
in flash i have
private function getBalanceAndXP():void
var request:URLRequest = new URLRequest("utils.php");
request.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.func = "getBalance";
variables.fbid = userID;
request.data = variables;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, onBalanceComplete);
loader.load(request);
private function onBalanceComplete(e:Event):void
var loader:URLLoader = e.target as URLLoader;
loader.removeEventListener(Event.COMPLETE, onBalanceComplete);
var variables:URLVariables = new URLVariables(loader.data);
_balance = parseInt(variables.balance); // class variable
_experience = parseInt(variables.experience); // class variable
public function setBalanceAndXP(balance:int, experience:int):void
_balance = balance;
_experience = experience;
var request:URLRequest = new URLRequest("utils.php");
request.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.func = "setBalance";
variables.fbid = userID;
variables.balance = _balance;
variables.experience = _experience;
request.data = variables;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load(request);
and then I have my php file
<?php
$func = $_POST["func"];
$fbid = $_POST["fbid"];
$balance = $_POST["balance"];
$experience = $_POST["experience"];
$numVariables = 0;
$link = mysql_connect("localhost","username","password");
mysql_select_db("databaseName");
if ($func == "getBalance")
getBalance($fbid);
else if ($func == "setBalance")
setBalance($fbid, $balance, $experience);
mysql_close($link);
function getBalance($fbid)
$query = "SELECT balance, experience FROM tableName WHERE fbid = '".$fbid."'";
$result = mysql_query($query);
$row = mysql_fetch_row($result);
writeVariable("balance", $row[0]);
writeVariable("experience", $row[1]);
function setBalance($fbid, $balance, $experience)
$query = "UPDATE tableName SET balance = ".$balance.", experience = ".$experience." WHERE fbid ='".$fbid."'";
mysql_query($query);
function writeVariable( $name, $value )
global $numVariables;
if ( $numVariables > 0 )
echo "&";
echo $name . "=" . urlencode($value);
$numVariables++;
?> -
Php to flash (beginners level)
<?php
require_once 'db_config.php';
$sql="SELECT * FROM guestbook";
$result=mysql_query($sql) or die(mysql_error());
$count=mysql_num_rows($result);
while ($data = mysql_fetch_assoc($result)){
$id = $data"[msg_id"];
$sender = $data["msg_sender"];
$subject = $data["msg_subject"];
$text = $data["msg"];
$date = $data["msg_date"];
echo($count);
echo($id);
echo($sender);
echo($subject);
echo($text);
echo($date);}
?>
wich gives me this result in a browser
Actionscript Code:
21Arnetest 1.2 3hallo, dit is een eerste test berichtje blablablabalba grtzzzzzzzzz2010-04-14 14:03:0022Arne Janssenshallo!test nog een keer2010-04-14 14:03:00
now is my question;
how can i write this code better, so that flash can handle it?
do i make an array of the results? ive been reading tutorials on this, but i cant figur it out ...
thx in advance for any help
grtzzzthis is how my codes looks now in flash
the first piece of code is for submitting the form
// php file
var phpFile:String = "http://localhost/portfolio/insertmessage.php";
// contact form
var form:MovieClip = guestbookform;
function sendMessage(e:MouseEvent):void
// first check the fields
var nameStr:String = form.nameTxt.text;
var subjectStr:String = form.subjectTxt.text;
var messageStr:String = form.msgTxt.text;
var allFields:Boolean = true;
// check name
if(nameStr.length < 2)
allFields = false;
// check subject
if(subjectStr.length < 2)
allFields = false;
// check message
if(messageStr.length < 2)
allFields = false;
if(!allFields)
trace("All required fields not filled in!");
form.statusTxt.htmlText = "<font color=\"#FF0000\">All required fields not filled in!</font>";
//Alert.show("All required not filled in!");
return;
var variables:URLVariables = new URLVariables();
variables.name = nameStr;
variables.subject = subjectStr;
variables.msg = messageStr;
var urlRequest:URLRequest = new URLRequest(phpFile);
urlRequest.method = URLRequestMethod.POST;
urlRequest.data = variables;
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, sendHandler);
loader.load(urlRequest);
function sendHandler(e:Event):void
var loader:URLLoader = URLLoader(e.target);
var variables:URLVariables = new URLVariables(loader.data);
trace(variables.test);
if(variables.resultCode == "SENT")
// message sent
form.statusTxt.htmlText = "<font color=\"#009933\">Email sent, thank you.</font>";
else if(variables.resultCode == "ERROR")
// message not sent
form.statusTxt.htmlText = "<font color=\"#FF0000\">Email not sent, please try again.</font>";
else
// unknown response
form.statusTxt.htmlText = "<font color=\"#FF0000\">Unknown ERROR</font>";
form.sendBtn.addEventListener(MouseEvent.CLICK, sendMessage);
var data:Array;
function completeHandler(event:Event):void {
var loader:URLLoader = URLLoader(event.target);
dataA = loader.data.split(",,,");
dataA.pop();
for(var i:uint=0;i<dataA.length;i++){
dataA[i] = dataA[i].split(",,");
dataA[i].shift();
dataHolder.text = data[1];
Maybe you are looking for
-
Bluetooth connection MacBook Pro 10.6.8 to iPad iOS 7.1
While attempting to transfer files from MacBook Pro 10.6.8 to iPad iOS 7.1 - otherwise properly "paired" - I am getting the message: your device (iPad) does not have the the necessary services. What kind of services? Is there any way how to install t
-
2 x 3 GHz Unknown in About This Mac?????
Anyone know what this means? Apple themselves can't explain it. I have a new 8-core, and in the About This Mac section, it says "2 x 3 GHZ Unknown.
-
Supply Chain in 11.03 and Multi-Org
Does Supply Chain cross Operating Units in 11.03? Are there sourcing rules that cross Operating Units (Item A, OU =A, is replenished/sourced from OU=B). I understand that Sourcing Rules are Global and Local, Global for an OU and Local for an Inventor
-
Write raw data to plist?
I've been trying this for over a day now, but to no avail. The specific reason is I have a bootcamp partition set up with Win7, and like to keep my Windows home folder in the Finder Sidebar, which requires some cajoling. I got it working the first ti
-
Hi Experts We are facing problem in logging into WebClient UI. The actual problem is that we are unable to get the framework when we click our profile. The display is blank. We have already maintained PFCG roles, Authorization roles, Business r