主场景 flash AS :
没有详细备注,不适合初学AS者阅读。。。
import mx.controls.gridclasses.DataGridColumn;
import mx.controls.Alert;
import flash.net.FileReferenceList;
import flash.net.FileReference;
import mx.managers.PopUpManager;
import mx.containers.Window;
//
Stage.scaleMode="noScale";
///
var siteReff:String = "";
_global.wriSiteFilesTreeXML = siteReff + "wriSiteFilesTreeXML.asp";
_global.rtnOneFolderFileXML = siteReff + "rtnOneFolderFileXML.asp";
_global.aspUploadPage = siteReff + "uploadfile.aspx";
_global.siteFolderTreeXML = siteReff + "siteFolderTreeXML.asp";
_global.AspCommand = siteReff + "AspCommand.asp";
_global.getWebsiteUsedSpace = siteReff + "getWebsiteUsedSpace.asp";
/
//定义全局功能函数end~~~~~~
_global.createEmptyContextMenu = function():ContextMenu {
var EmptyCM:ContextMenu = new ContextMenu();
EmptyCM.builtInItems.quality = false;
EmptyCM.builtInItems.print = false;
EmptyCM.builtInItems.zoom = false;
EmptyCM.builtInItems.play = false;
EmptyCM.builtInItems.loop = false;
EmptyCM.builtInItems.rewind = false;
EmptyCM.builtInItems.forward_back = false;
return EmptyCM;
};
function addRootCM():Void{
var TOOTcn_cm:ContextMenu = createEmptyContextMenu();
var aboutME:ContextMenuItem=new ContextMenuItem("关于TOOTcn",aboutTOOTcnFun);
var aboutMM:ContextMenuItem=new ContextMenuItem("联系TOOTcn",contactTOOTcnFun);
TOOTcn_cm.customItems.push(aboutME,aboutMM);
_root.menu=TOOTcn_cm;
}
addRootCM();
//
function aboutTOOTcnFun(){}
function contactTOOTcnFun(){getURL("mailto:toot2008@126.com","_self");}
//
var sampleImagePath:String = "";
///
function addFileTreeConMenu():Void{
var tr_productClass:ContextMenu = new ContextMenu();
tr_productClass.builtInItems.quality = false;
tr_productClass.builtInItems.print = false;
tr_productClass.builtInItems.zoom = false;
tr_productClass.builtInItems.play = false;
tr_productClass.builtInItems.loop = false;
tr_productClass.builtInItems.rewind = false;
tr_productClass.builtInItems.forward_back = false;
var refreshClassTree:ContextMenuItem = new ContextMenuItem("刷新", f_refreshFile);
var newFolderCM:ContextMenuItem = new ContextMenuItem("新建文件夹", f_newFolder);
newFolderCM.separatorBefore = true;
var addNewClass:ContextMenuItem = new ContextMenuItem("复制", f_copyFile);
addNewClass.separatorBefore = true;
var moveFolderCM:ContextMenuItem = new ContextMenuItem("移动", f_moveFolder);
var pastFolderCM:ContextMenuItem = new ContextMenuItem("粘贴", f_pastFolder);
var delNewClass:ContextMenuItem = new ContextMenuItem("删除", f_delFile);
delNewClass.separatorBefore = true;
var reNameFolder:ContextMenuItem = new ContextMenuItem("重命名", f_reNameFolderFun);
reNameFolder.separatorBefore = true;
tr_productClass.customItems.push(refreshClassTree,newFolderCM, addNewClass,moveFolderCM,pastFolderCM, delNewClass,reNameFolder);
tr_fileManager.menu = tr_productClass;
}
function f_refreshFile(evtObj:Object){ fileTreeDoLater();};
function f_newFolder(evtObj:Object){
var AspCmdStr:String = 'Set TOOTFileObject=Server.CreateObject("Scripting.FileSystemObject")';
AspCmdStr +=':TOOTFileObject.createFolder server.MapPath(/"'+txtCurrentPath.text.substr(11)+'/TOOTcn_'+random(9999)+ '/")';
AspCmdStr +=':set TOOTFileObject=nothing ';
dealFileFun(AspCmdStr , fileTreeDoLater);
};
function f_copyFile(evtObj:Object){
_global.folderOpe = "COPY";
_global.origFolderPath = txtCurrentPath.text.substr(11);
_global.origFolderName = evtObj.selectedItem.attributes["label"];
};
function f_moveFolder(evtObj:Object){
if(evtObj.selectedItem.attributes["label"] == undefined || txtCurrentPath.text=="/(SiteRoot)" ) return;
_global.folderOpe = "MOVE";
_global.origFolderPath = txtCurrentPath.text.substr(11);
_global.origFolderName = evtObj.selectedItem.attributes["label"];
};
function f_pastFolder(evtObj:Object){
if(_global.folderOpe == undefined || _global.origFolderPath == undefined) return;
var currentPath = txtCurrentPath.text.substr(11);
if(_global.folderOpe =="MOVE"){
if(_global.origFolderPath == currentPath ) return;
var AspCmdStr:String = 'Set TOOTFileObject=Server.CreateObject("Scripting.FileSystemObject")';
AspCmdStr +=':TOOTFileObject.moveFolder server.MapPath(/"'+ _global.origFolderPath+'/"),server.MapPath(/"'+currentPath+ '/'+_global.origFolderName +'/")';
AspCmdStr +=':set TOOTFileObject=nothing ';
dealFileFun(AspCmdStr , fileTreeDoLater);
_global.folderOpe =undefined;
_global.origFolderPath =undefined;
_global.origFolderName = undefined;
}else if(_global.folderOpe =="COPY"){
if(_global.origFolderPath == currentPath )
_global.origFolderName = _global.origFolderName + random(9999);
var AspCmdStr:String = 'Set TOOTFileObject=Server.CreateObject("Scripting.FileSystemObject")';
AspCmdStr +=':TOOTFileObject.copyFolder server.MapPath(/"'+ _global.origFolderPath+'/"),server.MapPath(/"'+currentPath+ '/'+_global.origFolderName +'/")';
AspCmdStr +=':set TOOTFileObject=nothing ';
dealFileFun(AspCmdStr , fileTreeDoLater);
}else
Alert.show("先执行 <复制> 命令 ....","Warnning!");
};
function f_delFile(evtObj:Object){
if(evtObj.selectedItem.attributes["label"] == undefined ) return;
var TOOTFun:Function = function(AlertEvtObj:Object){
if(AlertEvtObj.detail == Alert.CANCEL) return;
var currentPath:String = txtCurrentPath.text.substr(11);
var AspCmdStr:String = 'Set TOOTFileObject=Server.CreateObject("Scripting.FileSystemObject")';
AspCmdStr +=':TOOTFileObject.deleteFolder server.MapPath(/"'+currentPath+ '/")';
AspCmdStr +=':set TOOTFileObject=nothing ';
dealFileFun(AspCmdStr , fileTreeDoLater);
}
Alert.show("删除文件夹会删除所包含的所有内容 "+evtObj.selectedItem.attributes["label"]+" 要继续吗!","Warnning!",Alert.CANCEL|Alert.OK,_root,TOOTFun,null,Alert.CANCEL);
};
function f_reNameFolderFun(evtObj:Object){
if(evtObj.selectedItem.attributes["label"] == undefined ) return;
var TOOTWin = PopUpManager.createPopUp(tr_fileManager , Window, true, {contentPath:"reNameWinMC",title:"Rename folder name:"});
TOOTWin.setSize(280,140);
//
};
function reNameFolderFun(newNameStr:String){
var currentPath:String = txtCurrentPath.text.substr(11);
var AspCmdStr:String = 'Set TOOTFileObject=Server.CreateObject("Scripting.FileSystemObject")';
AspCmdStr +=':TOOTFileObject.moveFolder server.MapPath(/"'+currentPath+ '/"),server.MapPath(/"'+currentPath.substr(0,currentPath.lastIndexOf("/"))+"/"+newNameStr+'/")';
AspCmdStr +=':set TOOTFileObject=nothing ';
dealFileFun(AspCmdStr , fileTreeDoLater);
}
addFileTreeConMenu();
function fileTreeDoLaterLater(){
var resultXML:XML = new XML();
resultXML.ignoreWhite=true;
resultXML.onLoad=function(success:Boolean){
if(success){
tr_fileManager.dataProvider = this ;
loadFolderFile(_global.rtnOneFolderFileXML,txtCurrentPath.text.substr(11));
tr_fileManager.setIsOpen(tr_fileManager.getTreeNodeAt(0) , true ,false);
}else{
Alert.show("Cann't communicate with Server,please Check net connection....", "Error");
}
};
resultXML.load(_global.siteFolderTreeXML);
}
fileTreeDoLaterLater();
//
function fileTreeDoLater(){
var TOOTLvr:LoadVars = new LoadVars();
TOOTLvr.onLoad = function(success:Boolean){
if(success)
if(this["rtnMsg"]=="OK")
fileTreeDoLaterLater();
else
Alert.show("Progress error! Contact TOOT2008@126.com for technical support....", "Error");
else
Alert.show("Cann't communicate with Server,please Check net connection....", "Error");
};
TOOTLvr.load(_global.wriSiteFilesTreeXML);
}
/tree 是监听事件
var treeListener:Object = new Object();
treeListener.change = function(evt:Object) {
var selectedMP3:XMLNode = evt.target.selectedNode;
//if (evt.target.getIsBranch(selectedMP3)) {
var nodePath:String="";
for(var tmpParentNode:XMLNode = selectedMP3;tmpParentNode != null ; tmpParentNode = tmpParentNode.parentNode)
if(tmpParentNode.attributes['label'] )
if(tmpParentNode.attributes['nodeType'] == "folder")
nodePath ="/"+tmpParentNode.attributes['label'] + nodePath;
else
nodePath ="/" + tmpParentNode.attributes['label']+ nodePath;
txtCurrentPath.text=(nodePath);
if(selectedMP3.attributes['nodeType'] == "folder")
loadFolderFile(_global.fileDGAsp,nodePath.substr(11));
/ 计算文件数量 和 文件夹数量
var countFile:Number=0;
var countFolder:Number=0;
for(var tmpParentNode:XMLNode = selectedMP3.firstChild;tmpParentNode != null ; tmpParentNode = tmpParentNode.nextSibling )
if(tmpParentNode.hasChildNodes())
countFolder++;
else
countFile++;
txtFileCount.text ="文件夹 : " +countFolder + " 文件 : " + countFile;
//evt.target.setIsOpen(selectedMP3, !evt.target.getIsOpen(selectedMP3), true);
//} else {
//fillDG.changeDir(aspPath ,selectedMP3.attributes['flag']);//+selectedMP3.attributes['flag'] );
//currentPath=selectedMP3.attributes['flag'];
// txtCurrentPath.text="当前路径:"+(currentPath);
//}
}
tr_fileManager.addEventListener("change", treeListener);
///
/ fiel datagrid code segment.........
//
var name_dgc:DataGridColumn = new DataGridColumn("文件名");
name_dgc.headerText = "File Name";
name_dgc.width = 200;
// add the column to the DataGrid
name_dgc.editable=false;
dgFileList.addColumn(name_dgc);//
///
var space_dgc:DataGridColumn = new DataGridColumn("大小");
space_dgc.headerText = "Size";
space_dgc.width = 100;
space_dgc.editable=false;
dgFileList.addColumn(space_dgc);//
//
var type_dgc:DataGridColumn = new DataGridColumn("类型");
type_dgc.headerText = "Type";
type_dgc.width = 100;
type_dgc.editable=false;
dgFileList.addColumn(type_dgc);//
//
var modTime_dgc:DataGridColumn = new DataGridColumn("最后修改时间");
modTime_dgc.headerText = "Last Modify time";
modTime_dgc.width = 130;
modTime_dgc.editable=false;
dgFileList.addColumn(modTime_dgc);//
//
/// dg 的右键菜单/
var dgRMenu:ContextMenu = new ContextMenu();
dgRMenu.builtInItems.quality = false;
dgRMenu.builtInItems.print = false;
dgRMenu.builtInItems.zoom = false;
dgRMenu.builtInItems.play = false;
dgRMenu.builtInItems.loop = false;
dgRMenu.builtInItems.rewind = false;
dgRMenu.builtInItems.forward_back = false;
var refreshList:ContextMenuItem=new ContextMenuItem("刷新",refreshListF);
var addFItem:ContextMenuItem=new ContextMenuItem("上传文件到所选文件夹",addFItemF);
addFItem.separatorBefore = true;
var copyItem:ContextMenuItem=new ContextMenuItem("复制",copyFileFun);
copyItem.separatorBefore=true;
var pastItem:ContextMenuItem=new ContextMenuItem("粘贴",pastFileFun);
var delItem:ContextMenuItem=new ContextMenuItem("删除文件",delItemF);
delItem.separatorBefore=true;
var reName:ContextMenuItem=new ContextMenuItem("重命名模式",reNameF);
reName.separatorBefore=true;
dgRMenu.customItems.push(refreshList,addFItem,copyItem,pastItem,delItem,reName);
dgFileList.menu=dgRMenu;
dgFileList.hScrollPolicy="auto";
function addFItemF(evt:Object){ uploadFile(txtCurrentPath.text.substr(11)); }
function delItemF(evt:Object){
if (evt.selectedItem["文件名"] == undefined) return;
var TOOTAlertConfire:Function = function (evt_obj:Object) {
if (evt_obj.detail == Alert.OK) {
fileManager_del(txtCurrentPath.text.substr(11)+"/" + evt.selectedItem["文件名"] ) ;
}
};
Alert.show("确认要删除 ["+evt.selectedItem.文件名+"] 吗?", "Confirm!", Alert.OK | Alert.CANCEL, null, TOOTAlertConfire,"stockIcon" , Alert.CANCEL);//"progressBar1"
// ;
}
function refreshListF(){
fileTreeDoLater();
}
function reNameF(evtObj:Object){ evtObj.getColumnAt(0).editable =! evtObj.getColumnAt(0).editable;}
function copyFileFun(evtObj:Object){
if(evtObj.selectedItem["文件名"] == undefined) {
Alert.show("Please select a file first....","Warnning!");
return;
}
_global.Folder=txtCurrentPath.text.substr(11)+"/" ;
_global.FileName=evtObj.selectedItem["文件名"];
}
///
function pastFileFun(evt:Object){
if(_global.Folder==undefined || _global.FileName==undefined){
Alert.show("Please copy a file first....","warnning");
return;
}
var cmdStr:String="";
if ( _global.Folder == txtCurrentPath.text.substr(11)+"/"){
var tmpNum:Number = random(9999);
var newFilePath_Name:String= _global.Folder + _global.FileName.substr(0,-4)+tmpNum+_global.FileName.substr(-4);
}else{
var newFilePath_Name:String= txtCurrentPath.text.substr(11)+"/" + _global.FileName;
}
var aspCmdStr:String='Set MyFileObject=Server.CreateObject("Scripting.FileSystemObject")/n';
aspCmdStr+=': truePath=Server.MapPath(/"'+ _global.Folder + _global.FileName+'/")/n';
aspCmdStr+=':MyFileObject.copyfile truePath,Server.MapPath(/"'+newFilePath_Name+'/") /n';
aspCmdStr+=':set MyFileObject=nothing';
dealFileFun(aspCmdStr );
// trace(filePath_Name);
}
txtCurrentPath.text="/(SiteRoot)";
/
对文件重命名 功能函数
function reNameFun(evtObj:Object){
var folderPath:String = txtCurrentPath.text.substr(11)+"/";
var aspCmdStr:String='Set MyFileObject=Server.CreateObject("Scripting.FileSystemObject")/n';
aspCmdStr+=':MyFileObject.movefile server.mapPath(/"'+folderPath +evtObj.oldValue+'/"),server.mapPath(/"'+ folderPath+evtObj.target.selectedItem["文件名"]+'/") /n';
aspCmdStr+=':set MyFileObject=nothing';
dealFileFun(aspCmdStr );
}
dgFileList.addEventListener("cellEdit", reNameFun);
//按钮事件
var dgLstnObj:Object=new Object();
dgLstnObj.change = function (evt:Object){
var tmpFileName:String = evt.target.selectedItem["文件名"];
var exetenName:String =tmpFileName.substr(tmpFileName.lastIndexOf(".")+1,255).toLowerCase();
if(exetenName =="jpg" || exetenName =="gif" || exetenName =="jpeg" || exetenName =="png" || exetenName =="swf" )
sampleImagePath = txtCurrentPath.text.substr(11)+"/" +tmpFileName;
pb_sampleLdr.setProgress(0,100);
ldr_PicPrevious.load( sampleImagePath); /// 预览小图片
txtPicURL.text = sampleImagePath;
}
dgFileList.addEventListener("change",dgLstnObj);
function loadFolderFile(AspPageURL:String,path:String){
if(path == undefined) path = txtCurrentPath.text.substr(11);
if(path == undefined || path=="") path = "/";
var resultXML:XML = new XML();
resultXML.ignoreWhite=true;
resultXML.onLoad=function(success:Boolean){
if(success){
var tmpXML:XML = new XML(this.firstChild);
var tmpArr:Array = new Array();
var fileSizeTotal:Number = 0;
for(var tmpXMLNode:XMLNode=tmpXML.firstChild.firstChild; tmpXMLNode != null ; tmpXMLNode = tmpXMLNode.nextSibling)
{ var tmpObj:Object = new Object();
tmpObj["文件名"]=unescape(tmpXMLNode.attributes["label"]);
tmpObj["大小"]=int(Number(tmpXMLNode.attributes["fSize"])/1024 )+ " Kb";
tmpObj["类型"]=unescape(tmpXMLNode.attributes["fType"]);
tmpObj["最后修改时间"]=tmpXMLNode.attributes["fLastModified"];
fileSizeTotal += Number( tmpXMLNode.attributes["fSize"]) ;
tmpArr.push(tmpObj);
}
dgFileList.dataProvider = tmpArr ;
var tmpSizeStr:String = int(fileSizeTotal/1024)>=1024?( int(fileSizeTotal/1024/1024*1000)/1000 + " Mb "):(int(fileSizeTotal/1024) + " Kb ")
txtFileCount.text =" "+tmpArr.length + " file(s) / Total: " + tmpSizeStr ;
retrieSpaceInfo();
}
};
resultXML.load(_global.rtnOneFolderFileXML+ "?TOOTPath=" + escape(path) );
};
function retrieSpaceInfo():Void{
var resultLdr:LoadVars = new LoadVars();
resultLdr.onLoad = function (success:Boolean){
if(success){
var usedSpace:Number = int(Number(this["usedSpace"])/ 1024/1024*1000)/1000;
txtSvrSpaceInfo.text ="已用空间: "+ usedSpace + " Mb 可用 : " +(145-usedSpace) + " Mb " ;
}
}
resultLdr.load(_global.getWebsiteUsedSpace);
}
///
function fileManager_del(fileName ):Void{
if (fileName == undefined) return;
var aspCmdStr:String='Set MyFileObject=Server.CreateObject("Scripting.FileSystemObject")/n';
aspCmdStr+=': truePath=Server.MapPath(/"'+fileName+'/")/n';
aspCmdStr+=':MyFileObject.deletefile truePath /n';
aspCmdStr+=':set MyFileObject=nothing';
dealFileFun(aspCmdStr );
}
function dealFileFun(aspCmdStr:String,callFun:Function):Void{
var loadLvr:LoadVars = new LoadVars();
var sentLvr:LoadVars = new LoadVars();
loadLvr.onLoad = function(success:Boolean) {
if (success){
if(this["rtnMsg"]=="OK")
if(callFun)
callFun.call();
else
fileTreeDoLater();
}
}
sentLvr.tootcmd=aspCmdStr;
sentLvr.sendAndLoad( _global.AspCommand, loadLvr, "POST");
}
tr_fileManager.hScrollPolicy = "on";
tr_fileManager.maxHPosition = 300 ;
/
var fileArr:Array = new Array();
var winReff:Object;
var tmpN:Number=0;
var fileCount:Number=0;
var upLoadingItem:Object=null;
var lastFileFlag:Boolean = false;
function uploadFile(folderPath:String) {
var listener:Object = new Object();
listener.onSelect = function(fileRefList:FileReferenceList) {
++
var thisReff = this;
var win = PopUpManager.createPopUp(_root, Window, true, {contentPath:"upLoadingMC"});
winReff = win;
var winListener:Object = new Object();
winListener.complete = function(evt_obj:Object) {
winReff.content.btnCancelFile.onRelease=function(){
upLoadingItem.cancel();
fileArr=[];
winReff.deletePopUp();
Alert.show("User Terminate!", "Terminate!");
}
var item:FileReference;
for (var i:Number = 0; i<fileArr.length; i++) {
item = fileArr[i];
upLoadingItem=item;
win.content.lsAllFile.text += (item.name)+"/n";
//{label:item.name});
if (item.addListener(thisReff)) {
win.content.txtStaut.text = "成功监听上传动作....";
}
if(folderPath == "") folderPath = "/";
item.upload(_global.aspUploadPage+"?TOOTPath="+folderPath);
}
};
win.addEventListener("complete", winListener);
win.title = "上传文件";
win.setSize(500, 240);
win.move((Stage.width-win.width)/2, (Stage.height-win.height)/2);
++
fileArr = fileRefList.fileList;
tmpN = fileArr.length-1;
};
listener.onOpen = function(file:FileReference):Void {
winReff.content.txtCurrentFile.text = file.name;
};
listener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {
winReff.content.txtProgressShow.text = "Uploaded : "+bytesLoaded+" byte/nTotal : "+bytesTotal+"/nPercent :"+int(bytesLoaded/bytesTotal)*100+" %";
};
listener.onComplete = function(file:FileReference):Void {
//trace(fileCount);
winReff.content.lsOKFiles.text += file.name+"/n";
if (fileCount>=tmpN) {
winReff.deletePopUp();
Alert.show("Successfully upload file!", "Complete");
fileTreeDoLater();
}
/
fileCount++;
};
listener.onHTTPError = function(file:FileReference, httpError:Number):Void {
Alert.show("onHTTPError: "+file.name+" httpError: "+httpError, "Error!");
};
listener.onIOError = function(file:FileReference):Void {
trace("onIOError: "+file.name);
};
listener.onSecurityError = function(file:FileReference, errorString:String):Void {
trace("onSecurityError: "+file.name+" errorString: "+errorString);
};
var fileRef:FileReferenceList = new FileReferenceList();
fileRef.addListener(listener);
fileRef.browse();
}
///
var thisReff=this;
/
btn_viewPic.onRelease=function():Void{
if(ldr_PicPrevious.contentPath.length<5) return;
getURL(ldr_PicPrevious.contentPath,"_blank");
}
btn_copyURL.onRelease=function():Void{
if(ldr_PicPrevious.contentPath.length<5) return;
System.setClipboard(ldr_PicPrevious.contentPath );
}
btn_reloadPic.onRelease=function():Void{
if(ldr_PicPrevious.contentPath.length<5) return;
ldr_PicPrevious.load(ldr_PicPrevious.contentPath);
}
btn_Close.onRelease = function() {
getURL("/console/Loginout.asp","_self");
};
///
/
stop();