📄 xmlmenu.as
字号:
class XmlMenu
{
var m_parent_mc, m_menu_array, firstChild, data, childMenu, hitTest, parentMenu, subMenuVisible, onMouseMove;
function XmlMenu(xmlpath_str, parent_mc)
{
m_parent_mc = parent_mc;
m_menu_array = new Array();
this.initXML(xmlpath_str);
} // End of the function
function initXML(xmlpath_str)
{
var thisObj = this;
var menu_array = new Array();
var _loc9 = new XML();
_loc9.ignoreWhite = true;
_loc9.onLoad = function (success)
{
if (success)
{
for (var _loc5 = 0; _loc5 < firstChild.childNodes.length; ++_loc5)
{
var _loc3 = firstChild.childNodes[_loc5];
var _loc4 = new Array();
for (var _loc2 = 0; _loc2 < _loc3.childNodes.length; ++_loc2)
{
_loc4.push({caption: _loc3.childNodes[_loc2].attributes.name, href: _loc3.childNodes[_loc2].attributes.href});
} // end of for
menu_array.push({caption: _loc3.attributes.name, href: _loc3.attributes.href, subnav_array: _loc4});
} // end of for
thisObj.initMenu(menu_array);
} // end if
};
_loc9.load(xmlpath_str);
} // End of the function
function initMenu(nav_array)
{
var thisObj = this;
var _loc12 = 20;
var _loc13 = 20;
for (var _loc5 = 0; _loc5 < nav_array.length; ++_loc5)
{
var _loc4 = m_parent_mc.attachMovie("menu_mc", "menu" + _loc5 + "_mc", _loc5, {_x: _loc12, _y: _loc13});
_loc4.data = nav_array[_loc5];
m_menu_array.push(_loc4);
_loc4.label_txt.text = _loc4.data.caption;
var _loc2 = m_parent_mc.createEmptyMovieClip("submenu" + _loc5 + "_mc", _loc5 * 20 + 100);
_loc2._x = _loc12;
_loc2._y = _loc4._height;
_loc2.subMenuVisible = true;
this.hideSubMenu(_loc2);
_loc2.parentMenu = _loc4;
_loc2._visible = false;
var _loc6 = _loc13;
var _loc7 = _loc4.data.subnav_array;
for (var _loc15 = 0; _loc15 < _loc7.length; ++_loc15)
{
var _loc3 = _loc2.attachMovie("link_mc", "link" + _loc15 + "_mc", _loc15, {_x: 0, _y: _loc6});
_loc3.data = _loc7[_loc15];
_loc3.label_txt.text = _loc3.data.caption;
_loc3.onRelease = function ()
{
getURL(data.href, "_blank");
};
_loc6 = _loc6 + _loc3._height;
} // end of for
var _loc10 = _loc2._width + 1;
var _loc11 = _loc2._height + 1;
_loc2.beginFill(0, 0);
_loc2.moveTo(0, 0);
_loc2.lineTo(_loc10, 0);
_loc2.lineTo(_loc10, _loc11);
_loc2.lineTo(0, _loc11);
_loc2.lineTo(0, 0);
_loc2.endFill();
_loc4.childMenu = _loc2;
_loc12 = _loc12 + _loc4._width;
} // end of for
for (var _loc15 in m_menu_array)
{
m_menu_array[_loc15].onRollOver = function ()
{
thisObj.showSubMenu(childMenu);
};
m_menu_array[_loc15].onRelease = function ()
{
getURL(data.href, "_blank");
};
} // end of for...in
} // End of the function
function showSubMenu(target_mc)
{
var thisObj = this;
if (!target_mc.subMenuVisible)
{
this.hideAllSubMenus();
target_mc._visible = true;
target_mc.subMenuVisible = true;
target_mc.onMouseMove = function ()
{
var _loc3 = this.hitTest(_xmouse, _ymouse, true);
var _loc2 = parentMenu.hitTest(_xmouse, _ymouse, true);
if (!((_loc3 || _loc2) && subMenuVisible))
{
thisObj.hideSubMenu(this);
delete this.onMouseMove;
} // end if
};
} // end if
} // End of the function
function hideSubMenu(target_mc)
{
if (target_mc.subMenuVisible)
{
target_mc._visible = false;
target_mc.subMenuVisible = false;
} // end if
} // End of the function
function hideAllSubMenus()
{
for (var _loc2 in m_menu_array)
{
this.hideSubMenu(m_menu_array[_loc2].childMenu);
} // end of for...in
} // End of the function
function toggleSubMenu(target_mc)
{
target_mc.subMenuVisible ? (this.hideSubMenu(target_mc)) : (this.showSubMenu(target_mc));
} // End of the function
} // End of Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -