Flash
+ XML 菜单
无限级分类的XML菜单。/我甚至把我整个电脑的文件系统都写到XML里面去了。/
这个版本的功能为:
1。根据MXL的分类格式对菜单进行无限级别的无限内容的分类;
2。使用XML定制每个菜单的图标。/当然,如果您不想为每个菜单都定义一个,您只需要要全局中设置一个图标文件地址,这样,每个菜单将使用相同的图标;
3。类似的还有,定制每个单个菜单的文字颜色、文字大小、背景颜色、字体、打开链接的窗口;
4。在纯Flash的导航中,您可以使用asfunction:协议来进行通信;
5。如果您对这个XML菜单系统有所改进,可以将改进后的源代码发送给(FK)http://www.flashk.com/
全部打包下载
核心代码(已修正一Bug,时间2003-07-31):
Bug内容,关于图标的显示,Internet缓存。
//(FK)XML Menu Style1 www.flashk.com
//upDate from **************
// XML Menu Demo
// Coded by Darkvn 2003-0-03
// Mail: Darkvn@blueidea.com
// CopyRight(C) Blueidea.com
//***************
//to see the ever code visit http://www.blueidea.com/bbs/newsdetail.asp?id=997515
// (FK) WorkGroup
//2003-07-30
//Addres: http://www.flashk.com/shows/2003-7-30/
//for more information or see the least code update please visit the Addres
//code start >>>
stop();
//init the Stage
Stage.scaleMode = "noScale";
Stage.showMenu = 0;
// Unicode Surpport
System.useCodePage = true;
//load XML
menuData = new XML();
menuData.ignoreWhite = true;
menuData.onLoad = checkLoad;
menuData.load("menu.xml");
//判断XML是否加载成功
function checkLoad(loadSuccesss) {
if (loadSuccesss) {
creatRootMenu();
speed = Number(menuData.firstChild.attributes.moveSpeed);
lineHeight = Number(menuData.firstChild.attributes.lineHeight);
} else {
//显示错误信息(XML文件未找到)
_root.createTextField("showErrorInfo", 2, 0, 0, 150, Stage.height);
_root.showErrorInfo.text = "\n\n XML file not found!"+"\n\n"+"
you may try again.";
_root.showErrorInfo.textColor = 0xff0000;
var errorText = new TextFormat();
errorText.font = "Verdana";
errorText.size = 10;
_root.showErrorInfo.setTextFormat(errorText);
}
}
//建立顶级菜单
function creatRootMenu() {
_root.creatMyMenu(menuData.firstChild);
}
MovieClip.prototype.creatMenu = menuInit;
//创建通用菜单
function menuInit(a, b, c) {
if (a.firstChild.hasChildNodes && Number(a.attributes.open)) {
this.createEmptyMovieClip("item", b+11);
this.open = 1;
_root.creatMyMenu.call(this.item, a);
this.item._x = this._x+20;
} else {
this.open = 0;
}
if (c != 1) {
this.XMLData = a;
this.XMLIndex = b;
myItem = this;
this.onEnterFrame = function() {
var theUpper = this._parent["item"+(b-1)];
var dx = theUpper._y+theUpper._height+_root.lineHeight-this._y;
if (Math.abs(dx)>1) {
this._y += dx/_root.speed;
}
var fx = this.bg._height+_root.lineHeight-this.item._y;
if (Math.abs(fx)>1) {
this.item._y += fx/_root.speed;
}
};
_root.menuShowText.call(myItem, a);
_root.menuDrawBg.call(myItem, a);
}
}
//显示菜单背景图标
function menuDrawBg(a) {
this.createEmptyMovieClip("icon", 6);
this.myIcon = getConfigData.call(a, "icon");
this.myRightX = Number(getConfigData.call(a, "textSize"));
this.icon.loadMovie(this.myIcon);
var myBgColor = getConfigData.call(a, "bgColor");
this.createEmptyMovieClip("bg", 5);
this.bg._x = this.myRightX+10;
this.bg._alpha = 30;
this.bg.myHeight = this.myRightX+8;
with (this.bg) {
beginFill(myBgColor, 100);
moveTo(0, 0);
lineTo(2880, 0);
lineTo(2880, myHeight);
lineTo(0, myHeight);
lineTo(0, 0);
}
this.bg.onEnterFrame = function() {
if (this.over) {
if (this._alpha<99.5) {
this._alpha += (100-this._alpha)/3;
}
}
if (this.out) {
if (this._alpha>30.5) {
this._alpha += (30-this._alpha)/5;
}
}
};
this.bg.onRollOver = function() {
this.over = true;
this.out = false;
};
this.bg.onRollOut = function() {
this.over = false;
this.out = true;
};
this.bg.onReleaseOutSide = function() {
this.over = false;
this.out = true;
};
this.bg.onRelease = function() {
getURL(this._parent.XMLData.attributes.url, this._parent.XMLData.attributes.targetWindow);
if (!(Number(this._parent.XMLData.attributes.open))) {
this._parent.XMLData.attributes.open = 1;
this._parent.creatMenu(this._parent.XMLData, this._parent.XMLIndex, 1);
} else {
if (Number(this._parent.XMLData.attributes.open)) {
this._parent.item.removeMovieClip();
this._parent.XMLData.attributes.open = 0;
}
}
};
}
//显示菜单文字
function menuShowText(a) {
leftText = "-";
if (a.firstChild.hasChildNodes) {
leftText = "+";
}
var myTextcolor = getConfigData.call(a, "textColor");
this.myTextSize = Number(getConfigData.call(a, "textSize"));
var myFont = getConfigData.call(a, "font");
this.createTextField("info", 10, this.myTextSize+15, 0, 2880,
(this.myTextSize+8));
this.info.text = leftText+" "+a.attributes.info;
this.info.selectable = 0;
this.info.textColor = myTextColor;
var infoText = new TextFormat();
infoText.font = myFont;
infoText.size = this.myTextSize;
this.info.setTextFormat(infoText);
}
//获取私有配置信息
function getConfigData(a) {
if (this.attributes[a] == undefined) {
return menuData.firstChild.attributes[a];
} else {
return this.attributes[a];
}
}
//建立子菜单
function creatMyMenu(a, b) {
for (var i = 0; i<a.childNodes.length; i++) {
this.createEmptyMovieClip("item"+i, i);
var myMenu = this["item"+i];
myMenu.creatMenu(a.childNodes[i], i, b);
}
}
(FK)工作组
www.FlashK.com
2003-07-30
|