我有一个计划应用程序,允许用户保存任何更改。当用户单击“保存”按钮时,Flex会将所有信息发送到coldfusion脚本,该脚本会分离信息并将其保存到数据库中。这一切都运行良好,但我希望能够向用户显示某种文本,例如“您的文件已成功保存”或“出现错误。请联系管理员”。
我的AS功能如下:
import flash.net.URLLoader;
import flash.net.URLRequest;
private function save():void
{
var tempString:String = new String;
// Set up a URL request, loader, and variables
var progressOutURL:URLRequest = new URLRequest("saveSchedule.cfm");
var progressOutLoader:URLLoader = new URLLoader();
var progressOutVars:URLVariables = new URLVariables(); // Set the variables to be sent out
for (var i:int = 0; i < wholeProject.length; i++)
{
tempString = new String;
tempString = wholeProject[i].projectTitle + "|" + wholeProject[i].workingTitle + "|" + wholeProject[i].startDate + "|";
for (var j:int = 0; j < wholeProject[i].thisBlock.length; j++)
{
tempString = tempString + wholeProject[i].thisBlock[j].startOffset + "," + wholeProject[i].thisBlock[j].numDays + "," + wholeProject[i].thisBlock[j].role + "," + wholeProject[i].thisBlock[j].sID + "," + wholeProject[i].thisBlock[j].isConflict + "," + wholeProject[i].thisBlock[j].positionType + ";";
}
progressOutVars["project" + i] = tempString;
}
progressOutURL.method = URLRequestMethod.POST;
progressOutURL.data = progressOutVars;
progressOutLoader.load (progressOutURL);
}
我的coldfusion文件如下(现在它只保存信息的cfdump,以便我可以确保数据已发送):
<cfsavecontent variable="toOutput">
<cfdump var="#FORM#" />
</cfsavecontent>
<cffile action="write" file="#GetDirectoryFromPath(GetCurrentTemplatePath())#output.html" output="#toOutput#" />
有没有办法“progressOutLoader.load(progressOutURL);”返回一个布尔值或者说发送是否成功的东西?
答案 0 :(得分:2)
progressOutLoader.addEventListener(Event.COMPLETE,resultHandler);
public function resultHandler(event:Event):void {
Alert.show("Success");
}
同样处理其他事件。 http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html
为什么不使用Flex HTTPService?而不是URLLoader