您当前的位置:首页 > 网络学院 > Flash教程
Flash教程

FLASH+XML构造的下拉菜单

来源:番禺网站建设 作者:广州做网站 点击量:5718 添加时间:2008-07-16 21:41:19

用Tree组件来制作下拉菜单,会比较方便。但用FLASH AS打造下拉菜单会更灵活,而且最重要的是占用空间更小,只有2K多。一般用组件来完成的项目,都会自己开发的东西大一些。主要是使用XML分析。分析并获取XML的节点。转换成FLASH里面的元素。
1、制作显示菜单,以及下拉菜单;
2、编写XML文件;
3、添加AS。

fscommand("allowscale", "false");
//创建一个新的空 XML 对象
var my_xml:XML = new XML();
//取消空白节点输出
my_xml.ignoreWhite = true;
//加载xml
my_xml.load("
http://www.taoshaw.com/taoshaw/study/xml_listxiala/List.xml");
//判断是否加载成功,如果成功,则继续前进
my_xml.onLoad = function(ok:Boolean) {
  if (ok) {
    xml_Length = my_xml.firstChild.childNodes.length;
    //读取xml子节点的长度
    for (i=0; i<xml_Length; i++) {
      _root.attachMovie("mc", "mc"+i, i);
      _root["mc"+i]._y = 100;
      _root["mc"+i]._x = i*70+110;
      _root["mc"+i].txt = my_xml.firstChild.childNodes[i].attributes.nume;
      //读取菜单名称
    }
    //根据子节点来设置菜单
  } else {
    trace("加载XML失败!");
  }
};
_root.onMouseDown = function() {
  for (i=0; i<xml_Length; i++) {
    xml_Length2 = my_xml.firstChild.childNodes[i].childNodes.length;
    if (_root["mc"+i].hitTest(_root._xmouse, _root._ymouse)) {
      if (my_xml.firstChild.childNodes[i].hasChildNodes()) {
        for (j=0; j<xml_Length2; j++) {
          //调用子菜单元件
          _root.attachMovie("xialamc", "xialamc"+i+j, i+j+50);
          //读取子菜单名称
          _root["xialamc"+i+j].subtxt = my_xml.firstChild.childNodes[i].childNodes[j].attributes.subnume;
          //设置MC的默认座标
          _root["xialamc"+i+j]._x = i*70+168;
          _root["xialamc"+i+j]._y = j*30+128;
        }
      }
      //否则删除该菜单下的子菜单 
    } else {
      for (j=0; j<10; j++) {
        removeMovieClip(_root["xialamc"+i+j]);
      }
    }
  }
  //当然K为真时,打开网址
  if (k) {
    getURL(my_urll, _blank);
  }
};
//当鼠标触到菜单时,显示该菜单的子菜单 
_root.onMouseMove = function() {
  k = false;
  //当鼠标触及菜单时,菜单改变颜色 
  for (i=0; i<xml_Length; i++) {
    if (_root["mc"+i].hitTest(_root._xmouse, _root._ymouse)) {
      _root["mc"+i].gotoAndStop(2);
    } else {
      //否则仍旧为默认颜色
      _root["mc"+i].gotoAndStop(1);
    }
    for (j=0; j<10; j++) {
      //鼠标触发子菜单时,改变子菜单的颜色
      if (_root["xialamc"+i+j].hitTest(_root._xmouse, _root._ymouse)) {
        _root["xialamc"+i+j].gotoAndStop(11);
        //读取url值,并赋值给变量“my_urll”
        my_urll = my_xml.firstChild.childNodes[i].childNodes[j].attributes.url;
        //设置k为真
        k = true;
      } else if (_root["xialamc"+i+j]._currentframe != 10 && _root["xialamc"+i+j]._currentframe != 11) {
        _root["xialamc"+i+j].play();
      } else {
        //将xialamc内时间轴停在第10帧
        _root["xialamc"+i+j].gotoAndStop(10);
      }
    }
  }
};

发表评论 共有 条评论
用户名: 密码: 验证码: 匿名发表
咨询QQ:番禺网站建设149900898 番禺网络公司296823656 番禺网页设计466741366 番禺域名注册598784086 番禺域名注册(售后技术支持)296823656
咨询信箱:001#py001.com  001#001.gd.cn (请将#改为@)
免费咨询电话:4000-848485   咨询热线:020-8484 8485 / 84888958 / 33110440  传真:020-84888958   手机:13600028769
番禺区市桥地址:广州市番禺区大北路118号(番禺宾馆旁)来访前请预约
番禺零零壹网络(广州市灵易计算机软件有限公司) 法律顾问:广东威信律师事务所陈彬律师
《中华人民共和国增值电信业务经营许可证》 粤ICP备08100317号
请使用1024*768分辨率浏览本站以达到浏览企业建站的最佳视觉效果,如果您有任何番禺建网站,南沙,花都网页设计,网站空间,番禺域名注册,番禺企业邮局的问题请与我们联系