仿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=& ...
随机推荐
- 剑指offer系列40----机器人的运动范围
package com.exe8.offer; /** *[题目]地上有一个m行和n列的方格.一个机器人从坐标0,0的格子开始移动, * 每一次只能向左,右,上,下四个方向移动一格,但是不能进入行坐标 ...
- Func系列2:常用模块及API
简介 Func提供了非常丰富的功能模块,包括CommandModule(执行命令).CopyFileModule(拷贝文件).CPUModule(CPU信息).DiskModule(磁盘信息).Fil ...
- apidoc,一个相当不错的文档生成器
http://apidocjs.com/ 例子:myapp目录下的MyCode.java /** * * @api {get} /company/list 获取公司信息 * @apiName 获取公司 ...
- python安装psycopg2
vim ~/.bash_profile export PATH=/Applications/Postgres.app/Contents/Versions/9.4/bin/:$PATH pip inst ...
- free命令、buffer与cache的区别
freefree 命令相对于top 提供了更简洁的查看系统内存使用情况: # free total used free shared buffers cached Mem: 255988 231704 ...
- java学习笔记(三)字符串
字符串String 创建方法: 一·通过new创建 String str1= new String("abc"); 二 直接创建 String str2="abc ...
- ajax实现--技术细节详解
ajax原理和XmlHttpRequest对象 Ajax的原理简单来说通过XmlHttpRequest对象来向服务器发异步请求,从服务器获得数据,然后用javascript来操作DOM而更新页面.这其 ...
- Observer - IO (File Monitor)
1. 概述 有时被称作发布/订阅模式,观察者模式定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个主题对象.这个主题对象在状态发生变化时,会通知所有观察者对象,使它们能够自动更新自己. 2. ...
- HDU 2196 Computer 树形DP 经典题
给出一棵树,边有权值,求出离每一个节点最远的点的距离 树形DP,经典题 本来这道题是无根树,可以随意选择root, 但是根据输入数据的方式,选择root=1明显可以方便很多. 我们先把边权转化为点权, ...
- Android_ _开发技巧总结
=== 1 1.对于过多的控件,功能类似,数量又多的,可以用include方法.在实现应用中,可以把控件放入List集合中. private void initView() { // TODO ...