效果:

转载请注明: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空间相册的图片批量上传的更多相关文章

  1. KindEditor图片批量上传

    KindEditor编辑器图片批量上传采用了上传插件swfupload.swf,所以后台上传文件方法返回格式应为JSONObject的String格式(注). JSONObject格式: JSONOb ...

  2. OneThink实现多图片批量上传功能

    OneThink原生系统中的图片上传功能是uploadify.swf插件进行上传的,默认是只能上传一张图片的,但是uploadify.swf是支持多图片批量上传的,那么我们稍加改动就可实现OneThi ...

  3. asp.net+swfupload 多图片批量上传(附源码下载)

    asp.net的文件上传都是单个文件上传方式,无法执行一次性多张图片批量上传操作,要实现多图片批量上传需要借助于flash,通过flash选取多个图片(文件),然后再通过后端服务进行上传操作. 本次教 ...

  4. 利用WebUploader进行图片批量上传,在页面显示后选择多张图片压缩至指定路径【java】

    WebUploader是由Baidu WebFE(FEX)团队开发的一个简单的以HTML5为主,FLASH为辅的现代文件上传组件.在现代的浏览器里面能充分发挥HTML5的优势,同时又不摒弃主流IE浏览 ...

  5. PHP 多图上传,图片批量上传插件,webuploader.js,百度文件上传插件

    PHP  多图上传,图片批量上传插件,webuploader.js,百度文件上传插件(案例教程) WebUploader作用:http://fex.baidu.com/webuploader/gett ...

  6. Mvc利用淘宝Kissy uploader实现图片批量上传附带瀑布流的照片墙

    前言 KISSY 是由阿里集团前端工程师们发起创建的一个开源 JS 框架.它具备模块化.高扩展性.组件齐全,接口一致.自主开发.适合多种应用场景等特性.本人在一次项目中层使用这个uploader组件. ...

  7. Mvc Kissy uploader实现图片批量上传 附带瀑布流的照片墙

    前言 KISSY 是由阿里集团前端工程师们发起创建的一个开源 JS 框架.它具备模块化.高扩展性.组件齐全,接口一致.自主开发.适合多种应用场景等特性.本人在一次项目中层使用这个uploader组件. ...

  8. webuploader 实现图片批量上传

    1.导入资源 2.JSP代码 <div class="page-container"> <div class="row cl"> < ...

  9. JAVA图片批量上传JS-带预览功能

    这篇文章就简单的介绍一个很好用的文件上传工具,批量带预览功能.直接贴代码吧,都有注释,很好理解. HTML页面 <!DOCTYPE html> <%@ taglib prefix=& ...

随机推荐

  1. android学习笔记26——Activity

    Activity ==> android中四大组件:Activity.Service.BroadcastReceiver.ContentProvider Activity组件用于对用户呈现操作界 ...

  2. 五大Android布局方式浅析

    Android布局是应用界面开发的重要一环,在Android中,共有五种布局方式,分别是:FrameLayout(框架布局),LinearLayout (线性布局),AbsoluteLayout(绝对 ...

  3. 用C#将输入的小写字母转化为大写字母

    string A = "adsaf"; string B =""; B=A.ToUper();

  4. Codeforces Round #368 (Div. 2) D. Persistent Bookcase

    Persistent Bookcase Problem Description: Recently in school Alina has learned what are the persisten ...

  5. [物理学与PDEs]第4章习题参考解答

    [物理学与PDEs]第4章习题1 反应力学方程组形式的化约 - 动量方程与未燃流体质量平衡方程 [物理学与PDEs]第4章习题2 反应力学方程组形式的化约 - 能量守恒方程 [物理学与PDEs]第4章 ...

  6. LInux SSH远程文件/目录传输命令scp(转载)

    From:http://www.vpser.net/manage/scp.html 相信各位VPSer在使用VPS是经常会在不同VPS间相互备份数据或转移数据.一般情况下VPS都已安装了Ngnix或者 ...

  7. java中通过位运算实现多个状态的判断

    通过 <<  |  & ~ 位运算,实现同时拥有多个状态 通过 << 定义数据的状态 public interface LogConstants { /** * 消耗标 ...

  8. RadASM中文乱码问题解决方法!!

    RadASM版本:2.2.2.0 在这个版本的RadASM代码编辑器里面,如果输入中文,则会乱码,经过一些尝试后,终于解决了这个问题,通过修改RadASM的字体设置就可以了!! 修改字体说明:通过本人 ...

  9. crm 2011 plugin setparent setbusiness 用户更改经理 更改办事处

    背景: 在更改经理或者更改办事处时,使用plugin处理相应的团队. 问题:plugin写完,注册时发现使用update注册没有效果,然后bing得到,这里要使用setbusiness 和 setpa ...

  10. angularJs中的隐藏和显示

    <!DOCTYPE html> <html ng-app="a2_12"> <head> <meta charset="utf- ...