Flex中利用URLVariables和FileReference类Flex向服务器端脚本传送数据的例子 Flex脚本FlashColdFusionAdobe
程序员文章站
2022-05-06 22:37:35
...
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Applicationxmlns:mx="http://www.adobe.com/2006/mxml"
- layout="vertical"
- verticalAlign="middle"
- backgroundColor="white"
- creationComplete="init();">
- <mx:Script>
- <![CDATA[
- import flash.net.FileReference;
- import flash.net.URLRequestMethod;
- import mx.controls.Alert;
- import mx.utils.StringUtil;
- private var fileRef:FileReference;
- private var urlVars:URLVariables;
- private var urlReq:URLRequest;
- private var startTimer:Number;
- private var timer:Timer;
- private function init():void {
- fileRef = new FileReference();
- fileRef.addEventListener(Event.SELECT, fileRef_select);
- fileRef.addEventListener(Event.COMPLETE, fileRef_complete);
- fileRef.addEventListener(IOErrorEvent.IO_ERROR, fileRef_ioError);
- urlVars = new URLVariables();
- urlVars.userID = 94103;
- urlVars.fpVersion = flash.system.Capabilities.version;
- urlReq = new URLRequest();
- urlReq.method = URLRequestMethod.POST;
- urlReq.data = urlVars;
- urlReq.url = "http://localhost:8300/fileref/uploader.cfm";
- timer = new Timer(100);
- timer.addEventListener(TimerEvent.TIMER, onTimer);
- }
- private function onTimer(evt:TimerEvent):void {
- lbl.text = String(getTimer() - startTimer) + " ms";
- }
- private function start():void {
- fileRef.browse();
- }
- private function fileRef_select(evt:Event):void {
- fileRef.upload(urlReq);
- startTimer = getTimer();
- timer.start();
- }
- private function fileRef_complete(evt:Event):void {
- Alert.show(evt.toString(), evt.type);
- timer.stop();
- }
- private function fileRef_ioError(evt:IOErrorEvent):void {
- Alert.show(evt.text, evt.type);
- timer.stop();
- }
- ]]>
- </mx:Script>
- <mx:Buttonlabel="upload" click="start();" />
- <mx:Labelid="lbl" />
- </mx:Application>
下面是ColdFusion代码:
- <cfsilent><cfsetting enablecfoutputonly="true" />
- <cfsetreq = getHTTPRequestData( )>
- <cffileaction="UPLOAD" filefield="Filedata" destination="#ExpandPath('.')#" nameconflict="MAKEUNIQUE">
- <cfsavecontentvariable="info">
- <html>
- <head></head>
- <body>
- <cfdumplabel="CFFILE" var="#cffile#">
- <cfdumplabel="getHTTPRequestData()" var="#req#">
- <cfifIsDefined("FORM")>
- <cfdumplabel="FORM" var="#FORM#">
- </cfif>
- <cfifIsDefined("URL")>
- <cfdumplabel="URL" var="#URL#">
- </cfif>
- </body>
- </html>
- </cfsavecontent>
- <cffileaction="WRITE" file="#ExpandPath('./')##cffile.serverFileName#.dump.html" output="#info#" addnewline="Yes">
- </cfsilent><cfsettingenablecfoutputonly="false" />
- <cfcontentreset="true" />
- <cfoutput>fileName=#CFFILE.serverFile#&fileSize=#CFFILE.fileSize#</cfoutput>
上一篇: ASP.NET系统开发(二):漫话级联删除“三剑客”
下一篇: 对象增删改查与SQL查询操作方法