快速业务通道

纯AS代码实现可预览本地图片的flash上传客户端(as3.0)

作者 佚名技术 来源 服务器技术 浏览 发布时间 2012-07-07

需要Flash Player 10+版本的支持,原理就是主要利用fp10中的FileReference.load(),FileReference.data和 Loader.loadBytes()三个方法通过图片加载到内存中,来实现预览本地图片,但这个方式不太适用大图片预览,图片越大内存消耗就越大。 [注意]:

1.我这边图片上传路径是无效的,所以图片上传失败是正常的,你们可以改一下上传路径即可;

2.需要Flash Player 10的支持;

3.这次主要研究是预览本地图片功能。

演示效果: 实现代码: viewplaincopytoclipboardprint?
packageproject.test
{
importflash.display.*;
importflash.geom.Rectangle;
importflash.net.*;
importflash.text.*;
importflash.filters.*;
importflash.events.*;
importflash.system.Security;

importfl.controls.Button;
importfl.controls.ProgressBar;
importfl.controls.ProgressBarMode;

/**
*@linkkinglong@gmail.com
*@authorKinglong
*@playerversionfp10
*/
[SWF(width="500",height="300",frameRate="24",backgroundColor="#FFFFFF")]
publicclassTestUploadextendsSprite{

privateconstDEFAULT_UPLOAD_PAGE:String="http://test.klstudio.com/upload.ASP";
privateconstBOX_WIDTH:uint=500;
privateconstBOX_HEIGHT:uint=300;

privateconstSTATE_CACHE:String="cache";
privateconstSTATE_UPLOAD:String="upload";

privatevar_filters:Array;
privatevar_file:FileReference;
privatevar_loader:Loader;
privatevar_progress:ProgressBar;
privatevar_state:String;
privatevar_buttons:Array;
privatevar_labels:Array;
privatevar_txts:Array;
privatevar_rect:Rectangle;
privatevar_state_txt:TextField;

publicfunctionTestUpload(){
Security.allowDomain("*");

_buttons=[];
_txts=[];
_labels=["文件名称:","文件类型:","文件大小:","修改时间:"];

_rect=newRectangle(20,80,180,180);
_state=STATE_CACHE;

//背景;
this.graphics.beginFill(0x333333);
this.graphics.drawRoundRect(0,0,BOX_WIDTH,BOX_HEIGHT,10,10);
this.graphics.endFill();
this.graphics.beginFill(0xEFEFEF);
this.graphics.drawRoundRect(1,1,BOX_WIDTH-2,BOX_HEIGHT-2,10,10);
this.graphics.endFill();
this.graphics.beginFill(0x666666);
this.graphics.drawRoundRect(10,30,BOX_WIDTH-20,BOX_HEIGHT-60,20,20);
this.graphics.endFill();
this.graphics.beginFill(0xFEFEFE);
this.graphics.drawRoundRect(11,31,BOX_WIDTH-22,BOX_HEIGHT-62,20,20);
this.graphics.endFill();

this.graphics.beginFill(0xCCCCCC);
this.graphics.drawRect(11,70,BOX_WIDTH-22,1);
this.graphics.endFill();

this.graphics.beginFill(0x000000);
this.graphics.drawRect(_rect.x-1,_rect.y-1,_rect.width+2,_rect.height+2);
this.graphics.endFill();
this.graphics.beginFill(0xEEEEEE);
this.graphics.drawRect(_rect.x,_rect.y,_rect.width,_rect.height);
this.graphics.endFill();


//标题;
varlabel:TextField;
label=getLabel("图片上传(预览图片版)byKinglong",getTextFormat(0xFFFFFF,14,true));
label.x=10;
label.y=5;
label.filters=[getLabelFilter(0x000000)];
this.addChild(label);

for(vari:uint=0;i<_labels.length;i++){
label=getLabel(_labels[i],getTextFormat(0x333333,12),false,false);
label.x

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号