我有一个在Adobe Flash actionscript 3中创建的表单,需要帮助来验证我所做的是否正确...我是AS3和PHP的新手,所以任何帮助和解释都会非常感激。 ..
这是我的AS3编码....
processing_mc.visible = false;
function checkComplete(evt:MouseEvent):void {
// Create A new URLVariables instance to store the variable
var phpVars:URLVariables = new URLVariables();
// Create a variable (e.g. candidate) to send
phpVars.userFirstName = firstname_txt.text;
phpVars.userLastName = lastname_txt.text;
phpVars.userNumber = number_txt.text;
phpVars.userEmail = email_txt.text;
phpVars.userMsg = msg_txt.text;
// Create a new URLRequest instance sending data to "ascom01.php"
var myRequest:URLRequest = new URLRequest("form.php");
// Send data using the POST method
myRequest.method = URLRequestMethod.POST;
var loader:URLLoader = new URLLoader();
loader.load(myRequest);
loader.addEventListener(Event.COMPLETE, response);
function response(e:Event):void
{
trace(loader.data);
}
if(!firstname_txt.length) {
status_txt.text = "Please enter your first name";
} else if(!lastname_txt.length) {
status_txt.text = "Please enter your last name";
} else if (!email_txt.length) {
status_txt.text = "Please enter your email";
} else if (!number_txt.length) {
status_txt.text = "Please enter your phone number";
} else {
}
}
// handler for the PHP script completion and return of status
function completeHandler(event:Event):void {
processing_mc.visible = false;
firstname_txt.text = "";
lastname_txt.text = "";
email_txt.text = "";
number_txt.text = "";
msg_txt.text = "";
status_txt.text = event.target.data.return_msg;
}
// Add event listener for submit button click
submit_btn.addEventListener(MouseEvent.CLICK, checkComplete);
这是我的PHP编码,我刚开始工作....
<?php
if(isset($_POST['userFirstName']) && isset($_POST['userLastName']) && isset($_POST['userEmail']) && isset($_POST['userNumber']) && isset($_POST['userMsg']))
{
$userFirstName=strip_tags($_POST['userFirstName']);
$userLastName=strip_tags($_POST['userLastName']);
$userEmail=strip_tags($_POST['userEmail']);
$userNumber=strip_tags($_POST['userNumber']);
$userMsg=strip_tags($_POST['userMsg']);
// connect with database.
$username="******";
$password="******";
$database="b-elite-fitness";
mysql_connect("localhost","$username","$password") or die (mysql_error());
mysql_select_db("$database") or die (mysql_error());
//query for inserting data in database.
$query="INSERT INTO `formdp` VALUES('NULL','".mysql_real_escape_string($userFirstName)."','".mysql_real_escape_string($userLastName)."','".mysql_real_escape_string($userEmail)."','".mysql_real_escape_string($userNumber)."','".mysql_real_escape_string($userMsg)."')";
if($query_run=mysql_query($query))
{
echo'Data inserted.';
} else {
die(mysql_error());
}
}
?>
任何人都可以帮助我解决两者之间的联系......我已经在网上查了一下,每个例子都不同,不能理解它是如何工作的......
提前感谢DP
答案 0 :(得分:0)
如果通过连接表示将数据从AS3发送到PHP,则需要使用URLLoader
类。
您已准备好将数据与上面的URLRequest
实例一起使用,因此剩下要做的就是让您通过URLLoader
发送数据:
var loader:URLLoader = new URLLoader();
loader.load(myRequest);
您可以通过将Event.COMPLETE
的侦听器附加到URLLoader
来管理PHP脚本的响应。响应将存储在其data
属性中:
loader.addEventListener(Event.COMPLETE, response);
function response(e:Event):void
{
trace(loader.data);
}