Flash AS3表单组件 - PHP文件和Adobe Animate
符号'wholeForm',图层'动作',第1帧,第81行,第3列1120: 访问未定义的属性varLoader。符号'wholeForm',图层 '动作',第1帧,第81行,第18列1120:未定义的访问 property varSend。符号'wholeForm',图层'动作',第1帧,第1行 30,第27栏1067:类型值的隐含强制 flash.net:URL请求一个不相关的类型。
'wholeForm'是MovieClip
,其中包含按钮和文字,请参阅下图
代码:
import flash.net.URLVariables;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.Event;
import flash.events.MouseEvent;
//hide processing mc
processing_mc.visible = false;
//custom function we create to populate the comboBox
list
function addCountriesToList(): void {
countryList.addItem({
label: "Barja"
});
countryList.addItem({
label: "Baasir"
});
countryList.addItem({
label: "Jadra"
});
countryList.addItem({
label: "Jieh"
});
}
// Run function above now
addCountriesToList();
var variables: URLVariables = new URLVariables;
// Build the varSend variable
varSend: URLRequest = new URLRequest("from_parse.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
// Build the varLoader variable
varLoader: URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE, completeHandler);
// handler for the PHP script completion and return of status
function completeHandler(event: Event): void {
// remove processing clip
processing_mc.visible = false;
name_txt.text = "";
email_txt.text = "";
msg_txt.text = "";
//msg_txt.maxChars=300;
kids.value = 0;
checkBox.selected = false;
// Load the response frome php here
status_txt.text = event.target.data.return_msg;
}
// Add event listener for sumbit button click
sumbit_btn.addEventListener(MouseEvent.CLICK, ValidateAndSend);
// function ValidateAndSend
function ValidateAndSend(event: MouseEvent): void {
// validate fields
if (!name_txt.length) {
status_txt.text = "Plase enter your name";
} else if (!email_txt.length) {
status_txt.text = "Plase enter your mail";
} else if (!msg_txt.length) {
status_txt.text = "Plase enter your message";
} else {
// All is good, send the data now to PHP
processing_mc.visible = true;
// ready the variables in our form for sending
variables.userName = name_txt.text;
variables.userEmail = email_txt.text;
variables.userCountry = countryList.value;
variables.userKids = kids.value;
variables.userGender = radioGroup.value;
variables.Newsletter = checkBox.selected;
// Send the data to PHP now
varLoader.load(varSend);
} // close else conditin for error handling
} // close validate and send function
答案 0 :(得分:1)
由于没有解释问题,我猜你是说你有这些错误?
访问未定义的属性
varLoader
。访问未定义的属性
varSend
。将类型
flash.net:URLRequest
的值隐式强制转换为无关类型
他们说话。你没有声明变量,所以它们是未定义的......
声明为:var NAME : TYPE = VALUE;
示例:var myLoader : URLLoader = new URLLoader;
定义名为myLoader
的变量。
您的代码示例:
// Build the varSend variable
varSend: URLRequest = new URLRequest("from_parse.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
应该是
// Build the varSend variable
var varSend: URLRequest = new URLRequest("from_parse.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
所以修正案是:
代码:varLoader:URLLoader = new URLLoader;
已修复:var varLoader: URLLoader = new URLLoader
;
code:varSend:URLRequest = new URLRequest(" from_parse.php");
已修复:var varSend: URLRequest = new URLRequest("from_parse.php");
以上var varSend
(现已定义)也会修复以下错误:varLoader.load(varSend);
<强> PS:强>
对你和未来的读者来说,让代码更具可读性会更有帮助:
// Build the Sending variable
var mySend: URLRequest = new URLRequest("from_parse.php");
mySend.method = URLRequestMethod.POST;
mySend.data = variables;
// Build the Loading variable
var myLoader: URLLoader = new URLLoader;
myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
myLoader.addEventListener(Event.COMPLETE, completeHandler);
// Send the data to PHP now
myLoader.load(mySend);