| 首页 | 新闻 | 网页 | 设计 | 色彩 | 原创 | 视觉 | 素材 | 动漫 | 酷站 | 策划 | 文案 | 访谈 | 运营 | 编程 | 数据库 | 服务器 | 下载 | 图库 | 
您的位置: 幽幽天空 > 网页 > 网页制作 > Flash教程 > ActionScript教程 > 文章正文 用户登录
如何加入透明Flas
为新浪博客添加fl
flashget下载联盟
265联盟:“Flash
新易网络提供100M
龙太极/100m/asp/
无限网络提供50M 
霞光科技50M/Htm/
苏能科技100M/FTP
悠博科技50M/FTP/

flash和xml实现二级菜单效果           

flash和xml实现二级菜单效果

作者:佚名 来源:不详 更新:2007-1-13 20:36:50 错误报告 我要投稿
 P.S. 
    这个二级菜单程序已经很久之前写得了,这几天有一个网友再一次问起来,所以想一想还是把这个程序也贴出来吧,希望对大家有点帮助! 
演示效果: 

程序核心代码: 
//===主场景代码 ===   
stop();   
menu_xml_count = 0;   
menu_y = 30;   
id = 0;   
//读取menu.xml文件;   
menu_xml = new XML();   
menu_xml.ignoreWhite = true;   
menu_xml.onLoad = function(sc) {   
if (sc) {   
_root.init(this.firstChild);   
}   
};   
menu_xml.load("menu.xml");   
function init(nd) {   
menu_xml_count = nd.childNodes.length;   
setMenu(nd.firstChild);   
}   
function setMenu(node) {   
if (node != null) {   
var initObj = new Object();   
initObj._x = 0;   
if (menu_obj != undefined) {   
initObj._y = menu_obj._y+menu_obj._height;   
} else {   
initObj._y = menu_y;   
}   
initObj.id = id;   
initObj.node = node;   
initObj.label = node.attributes.label;   
initObj.target = node.attributes.target;   
initObj.goto = node.attributes.goto;   
menu_obj = _root.attachMovie("menu_mc", "menu"+id+"_mc", id+100, initObj);   
id = id+1;   
setMenu(node.nextSibling);   
} else {   
id = 0;   
fscommand("setHeight", menu_obj._y+menu_obj._height);   
play();   
}   
}   
function moveMenu(menu_id) {   
delete old_obj;   
for (i=0; i<menu_xml_count; i++) {   
var move_obj = eval("menu"+i+"_mc");   
if (menu_id == move_obj.id) {   
if (move_obj.opened) {   
move_obj.close_item();   
} else {   
move_obj.open_item();   
}   
} else {   
move_obj.close_item();   
}   
if (old_obj == undefined) {   
move_obj._y = menu_y;   
} else {   
move_obj._y = old_obj._y+old_obj._height;   
}   
old_obj = move_obj;   
}   
fscommand("setHeight", move_obj._y+move_obj._height);   
}   

//==== 一级菜单MC里代码====   
//初始化;   
opened = false;   
expand = false;   
sub_id = 0;   
label_en_txt.text = "Menu";   
label_cn_txt.text = "菜单名称";   
//设置label;   
if (label != undefined) {   
var label_arr = this.label.split("|");   
label_cn_txt.text = label_arr[0];   
label_en_txt.text = label_arr[1];   
}   
//===========;   
//设置expand;   
if (node.childNodes.length>0) {   
expand = true;   
}   
//===========;   
//设置target;   
if (this.target == undefined || this.target == "") {   
this.target = "_self";   
}   
if (!this.expand) {   
arrow_mc._visible = false;   
}   
//按钮事件;   
hit_btn.onPress = function() {   
menu_up();   
};   
hit_btn.onRollOver = function() {   
menu_over();   
};   
hit_btn.onRollOut = function() {   
menu_out();   
};   
hit_btn.onRelease = function() {   
menu_out();   
if (expand) {   
_root.moveMenu(this._parent.id);   
} else {   
gotoPage();   
}   
};   
hit_btn.onReleaseOutside = function() {   
menu_out();   
};   
function menu_over() {   
menu_mc.gotoAndPlay("over");   
}   
function menu_out() {   
menu_mc.gotoAndPlay("out");   
}   
function menu_up() {   
menu_mc.gotoAndStop("up");   
}   
function gotoPage() {   
if (this.goto != undefined && this.goto != "") {   
getURL(this.goto, this.target);   
}   
}   
function open_item() {   
this.createEmptyMovieClip("item_list_mc", 10);   
item_list_mc._y = 25;   
setMenu(node.firstChild);   
arrow_mc._rotation = 90;   
opened = true;   
}   
function close_item() {   
item_list_mc.removeMovieClip();   
arrow_mc._rotation = 0;   
opened = false;   
}   
function setMenu(nd) {   
if (nd != null) {   
var initObj = new Object();   
initObj._x = 0;   
if (item_obj != undefined) {   
initObj._y = item_obj._y+item_obj._height;   
} else {   
initObj._y = 0;   
}   
initObj.label = nd.attributes.label;   
initObj.target = nd.attributes.target;   
initObj.goto = nd.attributes.goto;   
item_obj = item_list_mc.attachMovie("item_mc", "item"+sub_id+"_mc", sub_id+100, initObj);   
var sub_obj = new Object();   
sub_obj._x = 0;   
sub_obj._y = 18;   
if (sub_id+1>=node.childNodes.length) {   
item_obj.attachMovie("line_menu_mc", "line_mc", 10, sub_obj);   
} else {   
item_obj.attachMovie("line_item_mc", "line_mc", 10, sub_obj);   
}   
sub_id = sub_id+1;   
setMenu(nd.nextSibling);   
} else {   
sub_id = 0;   
}   
}   


//=====二级菜单MC里的代码====   
//初始化;   
label_txt.text = "菜单名称";   
if (this.label != undefined) {   
label_txt.text = this.label;   
}   
color_out();   
//设置target;   
if (this.target == undefined || this.target == "") {   
this.target = "_self";   
}   
//按钮事件;   
hit_btn.onPress = function() {   
menu_up();   
color_over();   
};   
hit_btn.onRollOver = function() {   
menu_over();   
color_over();   
};   
hit_btn.onRollOut = function() {   
menu_out();   
color_out();   
};   
hit_btn.onRelease = function() {   
menu_out();   
color_out();   
gotoPage();   
};   
hit_btn.onReleaseOutside = function() {   
menu_out();   
color_out();   
};   
function menu_over() {   
item_mc.gotoAndPlay("over");   
}   
function menu_out() {   
item_mc.gotoAndPlay("out");   
}   
function menu_up() {   
item_mc.gotoAndStop("up");   
}   
function gotoPage() {   
if (this.goto != undefined && this.goto != "") {   
getURL(this.goto, this.target);   
}   
}   
function color_over() {   
label_txt.textColor = 0x000000;   
}   
function color_out() {   
label_txt.textColor = 0xffffff;   
}
文章录入:skyuu    责任编辑:skyuu 
  • 上一篇文章:

  • 下一篇文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    发表评论:
    姓名:  评 分: 1分 2分 3分 4分 5分
     
  • 严禁发表危害国家安全、政治、黄色淫秽等内容的评论。
  • 用户需对自己在使用幽幽天空服务过程中的行为承担法律责任。
  • 本站管理员有权保留或删除评论内容。
  • 评论内容只代表机友个人观点,与本网站立场无关。