仿qq空间相册的图片批量上传
效果:
转载请注明:http://www.cnblogs.com/TheViper/
主要是flash组件的tilelist,这个很有用。还有对flash组件源码的一点修改hack。
还是代码很简单,很不规范
package
{
import flash.display.*;
import flash.events.*;
import fl.data.DataProvider;
import fl.controls.TileList;
import flash.events.MouseEvent;
import fl.events.*;
import flash.net.*;
import flash.ui.*;
import fl.controls.listClasses.*;
import flash.external.*;
import fl.controls.ScrollBarDirection;
import fl.containers.*;
import flash.utils.Timer; public class PhotoUpload extends MovieClip
{
private var myTileList;
private var fileRef1:FileReference=new FileReference();
private var loader1:Loader;
private var fileRefList:CustomFileReferenceList;
private var fileList:Array = new Array ;
private var uploadlist:Array = new Array ;
//private var itemsArray:Array = new Array();
private var ori_index;
private var target_index;
private var hover_index;
private var max_x;
private var max_y;
private var url:String;
private var urlrequest:URLRequest = new URLRequest(url);
private var imgSizeList:Array = new Array ;
private var myTimer:Timer = new Timer(10);
private var myTimer1:Timer = new Timer(10); public function PhotoUpload()
{
myTimer.addEventListener("timer", timerHandler);
myTimer1.addEventListener("timer", timerHandler1);
myTileList = new TileList();
myTileList.direction = ScrollBarDirection.VERTICAL;
myTileList.columnWidth = 150;
myTileList.rowHeight = 150;
myTileList.rowCount = 6;
myTileList.move(14,14);
myTileList.setSize(990,660);
stage.addChildAt(myTileList,0);
myTileList.addEventListener(ListEvent.ITEM_ROLL_OVER, onItemHover);
wrap_control.addEventListener(MouseEvent.ROLL_OUT, onItemOut);
myTileList.addEventListener(ListEvent.ITEM_CLICK, onItemClick);
myTileList.addEventListener(MouseEvent.MOUSE_DOWN, onItemPress);
myTileList.addEventListener(MouseEvent.MOUSE_UP, onItemRelease);
boot.select_btn.addEventListener(MouseEvent.CLICK,selectFilesHandler1);
bottom_area.add_image1.addEventListener(MouseEvent.CLICK,selectFilesHandler1);
wrap_control.control.item_delete.addEventListener(MouseEvent.CLICK,deleteHandler);
bottom_area.upload_btn.addEventListener(MouseEvent.MOUSE_DOWN,function(e:Event){
do_upload(e,0);
});
bottom_area.visible = false;
}
public function timerHandler(event:TimerEvent):void
{
myTileList.verticalScrollPosition = myTileList.verticalScrollPosition + 5;
onItemMove(new MouseEvent(MouseEvent.MOUSE_MOVE));
}
public function timerHandler1(event:TimerEvent):void
{
myTileList.verticalScrollPosition = myTileList.verticalScrollPosition - 5;
onItemMove(new MouseEvent(MouseEvent.MOUSE_MOVE));
}
function selectFilesHandler1(event:MouseEvent):void
{
fileRefList = new CustomFileReferenceList ;
fileRefList.browse(getFilterTypes());
fileRefList.addEventListener(CustomFileReferenceList.SELECT_COMPLETE,selectHandler);
}
function getImagesFilter():FileFilter
{
return new FileFilter("images(*.jpg, *.gif, *.png, *.jpg)", "*.jpg;*.jpeg;*.gif;*.png");
}
function getFilterTypes():Array
{
return [getImagesFilter()];
}
function selectHandler(evt:Event):void
{
//if (uploadlist.length > 0)
//{
//itemsArray.pop();
//}
var fileRefList:CustomFileReferenceList = evt.target as CustomFileReferenceList;
fileRefList.removeEventListener(CustomFileReferenceList.SELECT_COMPLETE,selectHandler);
fileList = fileRefList.getSelectedFiles();
//var len:Number = uploadlist.length + fileList.length;
if (fileList.length > 0)
{
if ((uploadlist.length > 100))
{ }
else
{
if (myTileList.length > 0)
{
myTileList.removeItemAt(myTileList.length-1);
}
a(0,fileList);
}
}
}
function a(idx:Number,fileList:Array):void
{
var fileRef:FileReference = fileList[idx] as FileReference;
loadImage(fileRef,idx);
fileRef.load();
} function loadImage(fileRef:FileReference,idx:Number):void
{
fileRef.addEventListener(Event.COMPLETE,function()
{
var loader:Loader=new Loader();
resizeImage(loader, idx, fileRef);
loader.loadBytes(fileRef.data);
fileRef.removeEventListener(Event.COMPLETE, arguments.callee);
});
}
function resizeImage(loader:Loader,idx:Number,fileRef:FileReference):void
{
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,function(e:Event)
{
xmj(loader, idx, fileRef);
});
}
function xmj(loader:Loader,idx:Number,fileRef:FileReference)
{
var w:Number = loader.width;
var h:Number = loader.height;
var obj:Object = {w:w,h:h};
imgSizeList.push(obj);
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,arguments.callee);
var wrap_item:Sprite=new Sprite();
wrap_item.addChild(loader);
myTileList.addItem({source:wrap_item});
//itemsArray.push( {source:wrap_item} );
if ((idx < fileList.length - 1))
{
idx++;
if ((idx+uploadlist.length> 100))
{
//myTileList.addItem({source:add_image});
myTileList.addItem({source:add_image});
uploadlist = uploadlist.concat(fileList.slice(0,11));
trace("fffsafa");
}
else
{
//uploadlist = uploadlist.concat(fileList.slice(idx-1,idx));
bottom_area.visible = true;
boot.visible = false;
a(idx,fileList);
}
}
else
{
//itemsArray.push( {source:add_image} );
//var dp:DataProvider = new DataProvider(itemsArray);
//myTileList.dataProvider = dp;
//stage.addChildAt(myTileList,0);
myTileList.addItem({source:add_image});
trace(fileList.length);
if (fileList.length > 100)
{
uploadlist = uploadlist.concat(fileList.slice(0,9));
}
else
{
uploadlist = uploadlist.concat(fileList);
}
}
}
function onItemClick(event :ListEvent):void
{
if (event.index == uploadlist.length)
{
selectFilesHandler1(new MouseEvent(MouseEvent.CLICK));
}
}
function onItemHover(event :ListEvent):void
{
trace(event.index+" "+ uploadlist.length);
if (event.index < uploadlist.length)
{
wrap_control.visible = true;
max_x = uploadlist.length % 6;
max_y = Math.floor(uploadlist.length / 6);
var x_index:int = event.index % 6;
var y_index:int = event.index / 6;
if (y_index>max_y)
{
y_index = max_y;
}
if (y_index>=max_y&&x_index>max_x)
{
x_index = max_x;
}
wrap_control.x = 164 * (x_index ) + 14;
wrap_control.y = 164 * y_index + 100 - myTileList.verticalScrollPosition;
hover_index = event.index;
}
}
function deleteHandler(event:MouseEvent):void
{
myTileList.removeItemAt(hover_index);
uploadlist.splice(hover_index, 1);
wrap_control.visible = false;
if (uploadlist.length == 0)
{
bottom_area.visible =false;
boot.visible = true;
myTileList.removeItemAt(0);
}
}
function onItemOut(event :MouseEvent):void
{
wrap_control.visible = false;
}
function onItemPress(event : MouseEvent):void
{
wrap_control.visible = false;
if (event.target is ImageCell)
{
event.target.alpha = 0.2;
ori_index = event.target.listData.index;
var pb = event.target.getChildAt(1).getChildAt(1);
pb.width = 30;
wrap_control.visible = false;
myTileList.removeEventListener(ListEvent.ITEM_ROLL_OVER, onItemHover);
if (ori_index!=uploadlist.length)
{
Mouse.hide();
stage.addEventListener(MouseEvent.MOUSE_MOVE, onItemMove);
}
}
event.stopPropagation();
}
function onItemMove(event : MouseEvent):void
{
max_x = uploadlist.length % 6;
max_y = Math.floor(uploadlist.length / 6);
var x_index:int = myTileList.mouseX / 164;
var y_index:int = (myTileList.mouseY+myTileList.verticalScrollPosition) / 164;
if (y_index>max_y)
{
y_index = max_y;
}
if (y_index>=max_y&&x_index>max_x)
{
x_index = max_x;
}
custom_cursor.visible = true;
insert_flag.visible = true;
custom_cursor.x = stage.mouseX;
custom_cursor.y = stage.mouseY;
target_index = 6 * y_index + x_index;
insert_flag.x = 164 * (x_index) + 7;
insert_flag.y = 164 * y_index + 15 - myTileList.verticalScrollPosition;
if (stage.mouseY > 620)
{
myTimer.start();
}
else
{
myTimer.stop();
}
if (stage.mouseY < 40)
{
myTimer1.start();
}
else
{
myTimer1.stop();
}
}
function onItemRelease(event : MouseEvent):void
{
myTimer.stop();
myTimer1.stop();
event.target.alpha = 1;
//bottom_area.ab.text = "" + event.target;
if (ori_index != target_index && typeof target_index != "undefined" && ori_index != -1 && stage.hasEventListener(MouseEvent.MOUSE_MOVE) && target_index != -1)
{
var proxy = myTileList.getItemAt(ori_index);
myTileList.removeItemAt(ori_index);
if (target_index==uploadlist.length)
{
target_index = target_index - 1;
}
myTileList.addEventListener(ListEvent.ITEM_ROLL_OVER, onItemHover);
myTileList.addItemAt(proxy,target_index);
stage.removeEventListener(MouseEvent.MOUSE_MOVE, onItemMove);
Mouse.show();
}
ori_index = -1;
target_index = -1;
insert_flag.visible = false;
custom_cursor.visible = false;
}
private function do_upload(e:Event,i:int):void
{
var f:FileReference = uploadlist[i] as FileReference;
var obj:Object = imgSizeList[i];
try
{
f.upload(new URLRequest(this.url + "&w=" + obj["w"] + "&h=" + obj["h"]));
}
catch (e:Error)
{
trace(e.message);
}
f.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,function(e:DataEvent){
if(i<uploadlist.length-1){
i++;
do_upload(e,i);
}else{
ExternalInterface.call('img_upload_complete_all');
myTileList.removeAll();
uploadlist.length=0;
}
ExternalInterface.call('img_upload_complete',e.data);
});
}
}
}
改过的flash组件 http://files.cnblogs.com/TheViper/fl.zip
仿qq空间相册的图片批量上传的更多相关文章
- KindEditor图片批量上传
KindEditor编辑器图片批量上传采用了上传插件swfupload.swf,所以后台上传文件方法返回格式应为JSONObject的String格式(注). JSONObject格式: JSONOb ...
- OneThink实现多图片批量上传功能
OneThink原生系统中的图片上传功能是uploadify.swf插件进行上传的,默认是只能上传一张图片的,但是uploadify.swf是支持多图片批量上传的,那么我们稍加改动就可实现OneThi ...
- asp.net+swfupload 多图片批量上传(附源码下载)
asp.net的文件上传都是单个文件上传方式,无法执行一次性多张图片批量上传操作,要实现多图片批量上传需要借助于flash,通过flash选取多个图片(文件),然后再通过后端服务进行上传操作. 本次教 ...
- 利用WebUploader进行图片批量上传,在页面显示后选择多张图片压缩至指定路径【java】
WebUploader是由Baidu WebFE(FEX)团队开发的一个简单的以HTML5为主,FLASH为辅的现代文件上传组件.在现代的浏览器里面能充分发挥HTML5的优势,同时又不摒弃主流IE浏览 ...
- PHP 多图上传,图片批量上传插件,webuploader.js,百度文件上传插件
PHP 多图上传,图片批量上传插件,webuploader.js,百度文件上传插件(案例教程) WebUploader作用:http://fex.baidu.com/webuploader/gett ...
- Mvc利用淘宝Kissy uploader实现图片批量上传附带瀑布流的照片墙
前言 KISSY 是由阿里集团前端工程师们发起创建的一个开源 JS 框架.它具备模块化.高扩展性.组件齐全,接口一致.自主开发.适合多种应用场景等特性.本人在一次项目中层使用这个uploader组件. ...
- Mvc Kissy uploader实现图片批量上传 附带瀑布流的照片墙
前言 KISSY 是由阿里集团前端工程师们发起创建的一个开源 JS 框架.它具备模块化.高扩展性.组件齐全,接口一致.自主开发.适合多种应用场景等特性.本人在一次项目中层使用这个uploader组件. ...
- webuploader 实现图片批量上传
1.导入资源 2.JSP代码 <div class="page-container"> <div class="row cl"> < ...
- JAVA图片批量上传JS-带预览功能
这篇文章就简单的介绍一个很好用的文件上传工具,批量带预览功能.直接贴代码吧,都有注释,很好理解. HTML页面 <!DOCTYPE html> <%@ taglib prefix=& ...
随机推荐
- [svn]svn merge
转:http://blog.csdn.net/keda8997110/article/details/21813035 Step by Step 完成merge 目录: Branch的必要性 1.本地 ...
- MVC 模型
dbcontent var ALLALBUMS=from album in db.albums orderby album.title ascending select album; storeman ...
- Well, let's start everything from the very beginning.
帝都的霾仿佛亘古不变,不知觉2015年竟已快到尾声,而我在IBM也已呆了4个月.回顾过往多遇贵人,所获颇丰.最幸运的还是自己不忘初心,仍在不断成长.继续学习. 过去的几个月一直用WordPress,搭 ...
- NeHe OpenGL教程 第一课:OpenGL窗口
转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...
- [DNS] 网页无法打开,设置合适的DNS解决问题
一.缘由: 家里装的10M长城宽带,下载速度很快,就是打开网页会经常失败.播放视频会卡无法播放:最近尤甚,甚是恼怒. 在画个圈圈诅咒长城宽带的同时,突然想起来打不开网页很大可能是DNS解析失败导致,故 ...
- c++学习-链表
静态链表: #include<iostream> #include<string> using namespace std; struct book{ int num; flo ...
- c++学习-继承
继承 #include <iostream> using namespace std; class father{ public: void getHeight(){cout<< ...
- 申请iOS开发者证书
来源:http://blog.csdn.net/htttw/article/details/7939405 申请iOS开发者证书 今天我们介绍如何申请iOS开发者证书(99刀): 1. 打开 http ...
- C# 导出 Excel 和相关打印设置
源地址:http://blog.csdn.net/wanmingtom/article/details/6125599 Excel.Application myExcel = new Excel.Ap ...
- dede上怎么让所有链接在新窗口打开
网页的头部,添加:<base target="_blank"> <base target="_blank"> </head> ...