热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

flash上传类带自动压缩功能

现在相片比较大,好几M,直接上传比较麻烦package{importcom.adobe.images.JPGEncoder;importc

现在相片比较大,好几M,直接上传比较麻烦


package {import com.adobe.images.JPGEncoder;import com.adobe.images.PNGEncoder;import flash.display.Bitmap;import flash.display.BitmapData;import flash.display.DisplayObject;import flash.display.DisplayObjectContainer;import flash.display.Loader;import flash.display.LoaderInfo;import flash.display.Sprite;import flash.events.Event;import flash.events.IOErrorEvent;import flash.events.MouseEvent;import flash.geom.Matrix;import flash.geom.Rectangle;import flash.net.FileFilter;import flash.net.FileReference;import flash.utils.ByteArray;import flash.display.MovieClip;import fl.controls.Button;import flash.text.TextFormat;import flash.text.TextFieldAutoSize;import fl.controls.Label;import flash.external.ExternalInterface; import flash.net.FileFilter;import flash.net.FileReference;import flash.net.FileReferenceList;import flash.events.*; import flash.net.navigateToURL;import flash.net.URLRequest;import flash.net.URLVariables;import flash.events.Event;import flash.net.URLLoader;import flash.net.*;public class upload extends MovieClip {private var fileUpload:FileReferenceList = new FileReferenceList();private var serverUrl:String = 'upload.php';private var imgWidth:Number = 980;private var imgHeight:Number = 650;private var imgQuality:Number = 80;private var imgtype:Number = 0;private var jsFunction:String = ''; private var sessionid:String = ''; private var uploadid:String = ''; private var upfile:Array=new Array();private var btnname:String = "选择上传图片"; private var infobar:Label = new Label();public function upload() {// constructor codetrace("hello word!");var parameters:Object= root.loaderInfo.parameters;if(parameters != null){if(parameters["serverUrl"] != null){serverUrl = String(parameters["serverUrl"]);}if(parameters["imgWidth"] != null){imgWidth = Number(parameters["imgWidth"]);}if(parameters["imgHeight"] != null){imgHeight = Number(parameters["imgHeight"]);}if(parameters["imgQuality"] != null){imgQuality = Number(parameters["imgQuality"]);}if(parameters["jsFunction"] != null){jsFunction = String(parameters["jsFunction"]);}if(parameters["uploadid"] != null){uploadid = String(parameters["uploadid"]);}if(parameters["btnText"] != null){btnname = String(parameters["btnText"]);}if(parameters["sessionid"] != null){sessiOnid= String(parameters["sessionid"]);} if(parameters["imgtype"] != null){imgtype = Number(parameters["imgtype"]);} }var myButton:Button = new Button();myButton.label = btnname;myButton.width = 100;myButton.height = 30;myButton.move(10,10);var t1:TextFormat=new TextFormat();t1.bold=true;t1.size=14;myButton.setStyle("textFormat",t1);this.addChild(myButton);infobar.请选择图片,可以多选!";this.addChild(infobar);//点击事件,选择图片myButton.addEventListener(MouseEvent.CLICK,buttonClick);fileUpload.addEventListener(Event.SELECT, selectHandler);fileUpload.addEventListener(Event.COMPLETE, loadImageComplete); fileUpload.addEventListener(IOErrorEvent.IO_ERROR, function(evt:IOErrorEvent):void{infobar.text="加载图片失败!错误信息:" + evt.text;});fileUpload.addEventListener(SecurityErrorEvent.SECURITY_ERROR, function(evt:SecurityErrorEvent):void{infobar.text="加载图片失败!错误信息:" + evt.text;});}private function selectHandler(e:Event):void {//处理选择图片infobar.text="选择了"+ e.target.fileList.length +"个图片。";upfile=new Array();var file:FileReference; for (var i:uint = 0; i imgWidth || bitmap.height > imgHeight){if(bitmap.width > bitmap.height){ asize=imgWidth / bitmap.width;nw=true; } if(bitmap.height > bitmap.width){ bsize=imgHeight / bitmap.height; nh=true; } if(nw && nh){ if(asize imgHeight){bsize=Math.round((ysize-imgHeight)/2);ysize=imgHeight;}if(asize>imgWidth){asize=Math.round((asize-imgWidth)/2);xsize =imgWidth;} imageData= new BitmapData(xsize,ysize);shiftOrigin= new Matrix();shiftOrigin.scale(rsize,rsize); shiftOrigin.translate(-asize,-bsize); }else if(imgtype==1){//缩放到固定大小if(bitmap.width > imgWidth || bitmap.height > imgHeight){if(bitmap.width > imgWidth){ asize=imgWidth / bitmap.width;nw=true; } if(bitmap.height > imgHeight){ bsize=imgHeight / bitmap.height; nh=true; } if(nw && nh){ if(asize bitmap.width){xsize = bitmap.width;asize=0;}else{xsize = imgWidth;} if(imgHeight>bitmap.height){ysize = bitmap.height;bsize=0;}else{ysize = imgHeight;} imageData= new BitmapData(xsize,ysize);shiftOrigin= new Matrix();shiftOrigin.scale(rsize,rsize); shiftOrigin.translate(-asize,-bsize);}else{//默认不大于if(bitmap.width > imgWidth || bitmap.height > imgHeight){if(bitmap.width > imgWidth){ asize=imgWidth / bitmap.width;nw=true; } if(bitmap.height > imgHeight){ bsize=imgHeight / bitmap.height; nh=true; } if(nw && nh){ if(asize




推荐阅读
author-avatar
海and云
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有