最简单的flash上传文件代码

package
{
	import flash.display.*;
	import flash.text.*;
	import flash.events.DataEvent;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.SecurityErrorEvent;
	import flash.external.ExternalInterface;
	import flash.media.Camera;
	import flash.media.Microphone;
	import flash.net.XMLSocket;
	import flash.net.FileReference;
	import flash.net.URLRequest;
	import flash.net.URLVariables;
	import flash.events.MouseEvent;

	public class uploadify extends Sprite {

	private var xmlSocket:XMLSocket;
	private var fileRef:FileReference;
	private var url:String = "/path/to/upload";
	private var request:URLRequest = new URLRequest(url);
	private var param:Object = root.loaderInfo.parameters; // 取得FlashVars后面的所有参数
	
	public function uploadify():void {
		this.height = 25;
		this.width = 65;
		ExternalInterface.call("onLog",url);
		ExternalInterface.marshallExceptions = true;

		fileRef = new FileReference();
		fileRef.addEventListener(SecurityErrorEvent.SECURITY_ERROR,onError);
		fileRef.addEventListener(IOErrorEvent.IO_ERROR,onIoError);
		fileRef.addEventListener(Event.SELECT,onSelect);
		fileRef.addEventListener(Event.OPEN,onUpload);
		fileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,onComplete);
		ExternalInterface.call("onReady");

		var btn:Sprite = new Sprite();
		btn.graphics.beginFill(0xFFCC00);
		btn.graphics.drawRect(-100, -100, 1000,1000);
		this.addChild(btn);

		var text1:TextField = new TextField();
		text1.htmlText = param["text"];
		text1.selectable = false;
		text1.autoSize = TextFieldAutoSize.LEFT;
		text1.border = false;

		this.addChild(text1);

		text1.addEventListener(MouseEvent.CLICK,mouseOverListener);

	}

	private function mouseOverListener(e:MouseEvent):void{
		fileRef.browse();
	}

	private function onSelect(e:Event):void{
		url = param["url"];
		request = new URLRequest(url);
		fileRef.upload(request);
	}

	private function onComplete(e:DataEvent):void{
		ExternalInterface.call("onComplete",e.data.toString());
	}

	private function onUpload(e:Event):void{
		ExternalInterface.call("onUpload",e.toString());
	}

	private function onIoError(e:IOErrorEvent):void{
		ExternalInterface.call("onError",e.toString());
	}

	private function onError(e:SecurityErrorEvent):void{
		ExternalInterface.call("onError",e.toString());
	}

}

源码下载:uploadify