利用FLASH+ASP扫描文件夹实现图片展示功能
思路:
用ASP的FSO(这个思路是闪吧一位朋友在回贴中提到的,所以我才想起要做这个东东,呵呵)对象来扫描同文件夹下的JPG图片,并输出文件名
这里用ASP输出XML格式让FLASH加载,虽然不不太喜欢XML,但大家都觉得它规范一些,就输出它吧。
FLASH中的代码:
import flash.filters.BlurFilter;
import flash.filters.DropShadowFilter;
////============初始化===========
var b_filters:BlurFilter = new BlurFilter(5, 5, 1);
var d_filters:DropShadowFilter = new DropShadowFilter(5, 45, 0, 80, 10, 10);
var n:Number = new Number();
var url_array = new Array();
//这里是设置SWF与ASP的相对路径,虽然可以在ASP中比较得出,但感觉没有必要
var path_str:String = "images/";
function go_func() {
if (n<url_array.length-1) {
n++;
load_func();
} else {
trace("加载完成!");
}
}
//============MCL类===========
var _mcl:MovieClipLoader = new MovieClipLoader();
this.onLoadInit = function(_mc:MovieClip) {
_mc._txt.removeTextField();
_mc._width = 80;
_mc._height = 80;
_mc.filters = [b_filters, d_filters];
//============这里设置鼠标动作===========
_mc.onRollOver = function() {
this.filters = null;
};
_mc.onRollOut = function() {
this.filters = [b_filters, d_filters];
};
go_func();
};
//如果没有下面的代码,就会一个加载出错,导致后面的都不能加载,用这个可以出错时继续向下加载,源文件中我故意少了一个图片,让它出错
this.onLoadError = function(_mc:MovieClip) {
_mc.createTextField("_txt", 200, 20, 10, 60, 30);
_mc._txt.textColor = 0xff0000;
_mc._txt.text = "加载失败!";
go_func();
};
//=========加载进度显示==============
this.onLoadProgress = function(_mc:MovieClip, bytesLoaded:Number, bytesTotal:Number) {
_mc.createTextField("_txt", 200, 20, 10, 60, 30);
_mc._txt.textColor = 0xff0000;
_mc._txt.text = Math.floor((bytesLoaded/bytesTotal*10000)/100)+"%";
};
_mcl.addListener(this);
//=================load函数========
function load_func() {
this.createEmptyMovieClip("pic_mc"+n, n+100);
//如果要改成竖向加载,只需把下面的_x _y换一下就行了
this["pic_mc"+n]._y = 30+Math.floor(n/3)*100;
this["pic_mc"+n]._x = 100+n%3*100;
_mcl.loadClip(path_str+url_array[n], this["pic_mc"+n]);
}
//===========XML文件加载=========
var url_xml = new XML();
url_xml.ignoreWhite = true;
url_xml.onLoad = function(suc) {
if (suc) {
for (var d:Number = 0; d<this.firstChild.childNodes.length; d++) {
url_array.push(this.firstChild.childNodes[d].firstChild.nodeValue);
}
load_func();
} else {
trace("XML文件加载失败!");
}
};
url_xml.load(path_str+"showjpg.asp");
ASP:
复制内容到剪贴板代码:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Dim thisPath,FSO,fileItem,allFolder
thisPath = Server.MapPath(Request.ServerVariables("SCRIPT_NAME")) '得到ASP文件的路径
Set FSO = createobject("scripting.filesystemobject")'创建FSO对像
Set allFolder = FSO.GetFile(thisPath).parentfolder.files '得到ASP所在目录的父级对像,它就包括了这个ASP和我们放的图片
Response.write("<?xml version=""1.0"" encoding=""utf-8""?>")'开始输出XML
Response.ContentType = "text/XML"
Response.Write("<path>")
For Each fileItem In allFolder '想当于FLASH中的遍历,遍历整个对像中的元素
If lcase(right(fileItem.name,4))=".jpg" Then '如果后缀是JPG
Response.Write("<url>"+fileItem.name+"</url>")'就把它的文件名输出为XML的一个新节点
End If
Next
Response.Write("</path>")
Response.End()
%>
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |