打印

[基础] 请问如何给苹果菜单的按钮加上链接地址

如何给苹果菜单的按钮加上链接地址
演示效果:
引用:
//-----------------------------代码--------------------------------------------------
import flash.display.BitmapData;
//-------------------是否缓冲(false/true)---------------------------------------
var huanchong:Boolean = false;
//-------------------若缓冲为真-缓冲大小---------------------------------------
var huanchong_num:Number = 3;
var main_bg:BitmapData = BitmapData.loadBitmap("main_bg");
//-------------------铺背景--------------------------------
for (var j:Number = 0; j<=767; j++) {
this.createEmptyMovieClip("bg_mc"+j, this.getNextHighestDepth());
this["bg_mc"+j].attachBitmap(main_bg, this.getNextHighestDepth());
this["bg_mc"+j]._x = j*20-Math.floor(j/32)*640;
this["bg_mc"+j]._y = Math.floor(j/32)*20;
}
//-----------------链接名称--------------------------------
var menu_Array:Array = new Array();
menu_Array = ["主页", "联系", "Protfolio", "音乐", "电影", "历史", "日历", "链接", "RSS", "RSS2"];
//-----------------创建一个底条位图实例-------------------------
var flash8_菜鸟_kingofkofs:BitmapData = BitmapData.loadBitmap("dock_bg");
//-----------------创建一个MC用来加载位图对象----------------
_root.createEmptyMovieClip("setoff", _root.getNextHighestDepth());
for (var j:Number = 0; j<=menu_Array.length*4-1+2; j++) {
_root.setoff.createEmptyMovieClip("setoff_son"+j, _root.setoff.getNextHighestDepth());
_root.setoff["setoff_son"+j].attachBitmap(flash8_菜鸟_kingofkofs, _root.getNextHighestDepth(), "auto", true);
_root.setoff["setoff_son"+j]._x = j*10-210;
_root.setoff["setoff_son"+j]._y = -60;
_root.setoff._x = Stage.width/2-5;
_root.setoff._y = Stage.height;
_root.setoff._height = 50;
_root.setoff.ori_width = _root.setoff._width;
}
//-----------------创建MC以及加载库中的位图---------------------
for (var j:Number = 0; j<=menu_Array.length-1; j++) {
this[img[j]] = BitmapData.loadBitmap(menu_Array[j]);
_root.createEmptyMovieClip(menu_Array[j], _root.getNextHighestDepth());
_root[menu_Array[j]].createEmptyMovieClip("mc", _root.getNextHighestDepth());
_root[menu_Array[j]].mc.attachBitmap(this[img[j]], _root.getInstanceAtDepth(), "auto", true);
_root[menu_Array[j]].mc._width = 40;
_root[menu_Array[j]].mc._height = 40;
_root[menu_Array[j]].mc._x = -_root[menu_Array[j]]._width/2;
_root[menu_Array[j]].mc._y = -_root[menu_Array[j]]._height;
_root[menu_Array[j]]._x = j*_root[menu_Array[j]]._width+(Stage.width-_root[menu_Array[j]]._width*menu_Array.length)*0.5+15;
_root[menu_Array[j]]._y = Stage.height;
_root[menu_Array[j]].ori_x = _root[menu_Array[j]]._x;
_root[menu_Array[j]].ori_y = _root[menu_Array[j]]._y;
_root[menu_Array[j]].ori_wid = _root[menu_Array[j]]._width;
_root[menu_Array[j]].ori_hei = _root[menu_Array[j]]._height;
//trace(_root[menu_Array[j]].ori_x);
}
var all_wid:Number = 0;
_root.createEmptyMovieClip("point", _root.getNextHighestDepth());
setInterval(function () {
updateAfterEvent();
_root.all_wid = _root[menu_Array[0]]._width+_root[menu_Array[1]]._width+_root[menu_Array[2]]._width+_root[menu_Array[3]]._width+_root[menu_Array[4]]._width+_root[menu_Array[5]]._width+_root[menu_Array[6]]._width+_root[menu_Array[7]]._width+_root[menu_Array[8]]._width+_root[menu_Array[9]]._width;
_root.setoff._width = (_root.all_wid-400)+_root.setoff.ori_width;
if (!huanchong) {
  _root.point._x = _xmouse;
  _root.point._y = _ymouse;
} else {
  _root.point._x += (_xmouse-_root.point._x)/huanchong_num;
  _root.point._y += (_ymouse-_root.point._y)/huanchong_num;
}
for (var j:Number = 0; j<=menu_Array.length-1; j++) {
  //-------------------计算及设置鼠标滑过时MC的高低----------------
  if (_root.point._x>=_root[menu_Array[j]].ori_x && _root.point._x-_root[menu_Array[j]].ori_x<=_root[menu_Array[j]].ori_wid*2.5 && _root.point._y<_root[menu_Array[j]]._y && _root[menu_Array[j]]._y-_root.point._y<=_root[menu_Array[j]].ori_hei*2.5) {
   _root["percent_x"+j] = 1-(_root.point._x-_root[menu_Array[j]].ori_x)/(_root[menu_Array[j]].ori_wid*2.5);
   _root["percent_y"+j] = 1-((_root[menu_Array[j]]._y-_root[menu_Array[j]].ori_wid)-_root.point._y)/(_root[menu_Array[j]].ori_hei*2.5-20);
   if (_root["percent_y"+j]>=1) {
    _root["percent_y"+j] = 1;
   }
   _root["percent_xy"+j] = _root["percent_x"+j]*_root["percent_y"+j];
   _root[menu_Array[j]]._width = _root["percent_xy"+j]*60+40;
   _root[menu_Array[j]]._height = _root["percent_xy"+j]*60+40;
  } else if (_root.point._x<_root[menu_Array[j]].ori_x && _root[menu_Array[j]].ori_x-_root.point._x<_root[menu_Array[j]].ori_wid*2.5 && _root.point._y<_root[menu_Array[j]]._y && _root[menu_Array[j]]._y-_root.point._y<=_root[menu_Array[j]].ori_hei*2.5) {
   _root["percent_x"+j] = 1-(_root[menu_Array[j]].ori_x-_root.point._x)/(_root[menu_Array[j]].ori_wid*2.5);
   _root["percent_y"+j] = 1-((_root[menu_Array[j]]._y-_root[menu_Array[j]].ori_wid)-_root.point._y)/(_root[menu_Array[j]].ori_hei*2.5-20);
   if (_root["percent_y"+j]>=1) {
    _root["percent_y"+j] = 1;
   }
   _root["percent_xy"+j] = _root["percent_x"+j]*_root["percent_y"+j];
   _root[menu_Array[j]]._width = _root["percent_xy"+j]*60+40;
   _root[menu_Array[j]]._height = _root["percent_xy"+j]*60+40;
  } else if (huanchong) {
   _root[menu_Array[j]]._width -= (_root[menu_Array[j]]._width-40)/5;
   _root[menu_Array[j]]._height -= (_root[menu_Array[j]]._height-40)/5;
  } else {
   _root[menu_Array[j]]._width = 40;
   _root[menu_Array[j]]._height = 40;
  }
  //-------------------菜单提示TXT----------------
  _root[menu_Array[j]].onRollOver = function() {
   this.menu_name = true;
   this.swapDepths(_root.getNextHighestDepth());
  };
  _root[menu_Array[j]].onRollOut = function() {
   this.menu_name = false;
  };
  if (_root[menu_Array[j]].menu_name) {
   _root.createTextField(menu_Array[j]+"txt", _root.getNextHighestDepth(), -10, -40, 50, 30);
   _root[menu_Array[j]+"txt"].bold = true;
   _root[menu_Array[j]+"txt"].text = menu_Array[j];
   _root[menu_Array[j]+"txt"]._xscale = _root[menu_Array[j]+"txt"]._yscale=150;
   _root[menu_Array[j]+"txt"].textColor = 0x000000;
   _root[menu_Array[j]+"txt"]._x = _root[menu_Array[j]]._x-_root[menu_Array[j]+"txt"]._width/2;
   _root[menu_Array[j]+"txt"]._y = Stage.height-_root[menu_Array[j]]._height-20;
   _root[menu_Array[j]+"txt"].selectable = false;
  } else {
   _root[menu_Array[j]+"txt"].removeTextField();
  }
}
_root[menu_Array[0]]._x = _root.setoff._x-_root.setoff._width/2+_root[menu_Array[0]]._width/2+10;
for (var j:Number = 1; j<=menu_Array.length-1; j++) {
  _root[menu_Array[j]]._x = _root[menu_Array[j-1]]._x+_root[menu_Array[j-1]]._width/2+_root[menu_Array[j]]._width/2;
}
}, 10);
原文件下载
http://space.flash8.net/bbs/attachment.php?aid=331878

[ 本帖最后由 yibin616 于 2008-6-17 10:17 编辑 ]
给每个MC添加一个onRelease事件,并getRUL
http://www.flash023.cn 终极讨厌
因为LZ没有贴FLA文件,我这就写链接的部分
复制内容到剪贴板
代码:
menu_URL = ["index.html", "联系.html", "Protfolio.html", "音乐.html", "电影.html", "历史.html", "日历.html", "链接.html", "RSS.html", "RSS2.html"];
在_root[menu_Array[j]].mc.attachBitmap(this[img[j]], _root.getInstanceAtDepth(), "auto", true);后加上
_root[menu_Array[j]].mc.id = j;
_root[menu_Array[j]].mc.onPress = function (){
getURL(menu_URL[j]);
}
手写没有测试,你自己再调试下吧
楼上的代码会有问题
链接会全是一样的
http://www.flash023.cn 终极讨厌

TOP

还在为头像烦恼?还在为不能关注好友动态烦忧?快来蓝色理想家园吧!
引用:
原帖由 libins 于 2008-6-17 09:59 发表
因为LZ没有贴FLA文件,我这就写链接的部分
menu_URL = ["index.html", "联系.html", "Protfolio.html", "音乐.html", "电影.html", "历史.html", "日历.html", "链接.html", "RSS.html", "RSS2.html"];

在_root[ ...
还没有实现
谢谢你哦~~~~
原文件已提供,麻烦高手给我测试一下,还有就是怎么把它的位置网上移

TOP

getURL(menu_URL [this.id]);

笔误笔误,谢谢斑竹指正

TOP

晕死,不能上传,超过尺寸了
复制内容到剪贴板
代码:
import flash.display.BitmapData;
//-------------------是否缓冲(false/true)------------------------------
var huanchong:Boolean = false;
//-------------------若缓冲为真-缓冲大小---------------------------------------
var huanchong_num:Number = 3;
var main_bg:BitmapData = BitmapData.loadBitmap("main_bg");
//-------------------铺背景--------------------------------
for (var j:Number = 0; j<=767; j++) {
    this.createEmptyMovieClip("bg_mc"+j,this.getNextHighestDepth());
    this["bg_mc"+j].attachBitmap(main_bg,this.getNextHighestDepth());
    this["bg_mc"+j]._x = j*20-Math.floor(j/32)*640;
    this["bg_mc"+j]._y = Math.floor(j/32)*20;
}
//-----------------链接名称--------------------------------
var menu_Array:Array = new Array();
menu_Array = ["主页", "联系", "Protfolio", "音乐", "电影", "历史", "日历", "链接", "RSS", "RSS2"];
menu_URL = ["index.html", "联系.html", "Protfolio.html", "音乐.html", "电影.html", "历史.html", "日历.html", "链接.html", "RSS.html", "RSS2.html"];
//-----------------创建一个底条位图实例-------------------------
var flash8_菜鸟_kingofkofs:BitmapData = BitmapData.loadBitmap("dock_bg");
//-----------------创建一个MC用来加载位图对象----------------
_root.createEmptyMovieClip("setoff",_root.getNextHighestDepth());
for (var j:Number = 0; j<=menu_Array.length*4-1+2; j++) {
    _root.setoff.createEmptyMovieClip("setoff_son"+j,_root.setoff.getNextHighestDepth());
    _root.setoff["setoff_son"+j].attachBitmap(flash8_菜鸟_kingofkofs,_root.getNextHighestDepth(),"auto",true);
    _root.setoff["setoff_son"+j]._x = j*10-210;
    _root.setoff["setoff_son"+j]._y = -60;
    _root.setoff._x = Stage.width/2-5;
    _root.setoff._y = Stage.height;
    _root.setoff._height = 50;
    _root.setoff.ori_width = _root.setoff._width;
}
//-----------------创建MC以及加载库中的位图---------------------
for (var j:Number = 0; j<=menu_Array.length-1; j++) {
    this[img[j]] = BitmapData.loadBitmap(menu_Array[j]);
    _root.createEmptyMovieClip(menu_Array[j],_root.getNextHighestDepth());
    _root[menu_Array[j]].createEmptyMovieClip("mc",_root.getNextHighestDepth());
    _root[menu_Array[j]].mc.attachBitmap(this[img[j]],_root.getInstanceAtDepth(),"auto",true);
    _root[menu_Array[j]].id = j;
    _root[menu_Array[j]].mc._width = 40;
    _root[menu_Array[j]].mc._height = 40;
    _root[menu_Array[j]].mc._x = -_root[menu_Array[j]]._width/2;
    _root[menu_Array[j]].mc._y = -_root[menu_Array[j]]._height-20;//这里可以改动图标Y的坐标,上移20
    _root[menu_Array[j]]._x = j*_root[menu_Array[j]]._width+(Stage.width-_root[menu_Array[j]]._width*menu_Array.length)*0.5+15;
    _root[menu_Array[j]]._y = Stage.height;
    _root[menu_Array[j]].ori_x = _root[menu_Array[j]]._x;
    _root[menu_Array[j]].ori_y = _root[menu_Array[j]]._y;
    _root[menu_Array[j]].ori_wid = _root[menu_Array[j]]._width;
    _root[menu_Array[j]].ori_hei = _root[menu_Array[j]]._height;
    //trace(_root[menu_Array[j]].ori_x);
}
var all_wid:Number = 0;
_root.createEmptyMovieClip("point",_root.getNextHighestDepth());
setInterval(function () {
updateAfterEvent();
_root.all_wid = _root[menu_Array[0]]._width+_root[menu_Array[1]]._width+_root[menu_Array[2]]._width+_root[menu_Array[3]]._width+_root[menu_Array[4]]._width+_root[menu_Array[5]]._width+_root[menu_Array[6]]._width+_root[menu_Array[7]]._width+_root[menu_Array[8]]._width+_root[menu_Array[9]]._width;
_root.setoff._width = (_root.all_wid-400)+_root.setoff.ori_width;
if (!huanchong) {
_root.point._x = _xmouse;
_root.point._y = _ymouse;
} else {
_root.point._x += (_xmouse-_root.point._x)/huanchong_num;
_root.point._y += (_ymouse-_root.point._y)/huanchong_num;
}
for (var j:Number = 0; j<=menu_Array.length-1; j++) {
//-------------------计算及设置鼠标滑过时MC的高低----------------
if (_root.point._x>=_root[menu_Array[j]].ori_x && _root.point._x-_root[menu_Array[j]].ori_x<=_root[menu_Array[j]].ori_wid*2.5 && _root.point._y<_root[menu_Array[j]]._y && _root[menu_Array[j]]._y-_root.point._y<=_root[menu_Array[j]].ori_hei*2.5) {
_root["percent_x"+j] = 1-(_root.point._x-_root[menu_Array[j]].ori_x)/(_root[menu_Array[j]].ori_wid*2.5);
_root["percent_y"+j] = 1-((_root[menu_Array[j]]._y-20)-_root.point._y)/(_root[menu_Array[j]].ori_hei*2.5-20);
if (_root["percent_y"+j]>=1) {
_root["percent_y"+j] = 1;
}
_root["percent_xy"+j] = _root["percent_x"+j]*_root["percent_y"+j];
_root[menu_Array[j]]._width = _root["percent_xy"+j]*60+40;
_root[menu_Array[j]]._height = _root["percent_xy"+j]*60+40;
} else if (_root.point._x<_root[menu_Array[j]].ori_x && _root[menu_Array[j]].ori_x-_root.point._x<_root[menu_Array[j]].ori_wid*2.5 && _root.point._y<_root[menu_Array[j]]._y && _root[menu_Array[j]]._y-_root.point._y<=_root[menu_Array[j]].ori_hei*2.5) {
_root["percent_x"+j] = 1-(_root[menu_Array[j]].ori_x-_root.point._x)/(_root[menu_Array[j]].ori_wid*2.5);
_root["percent_y"+j] = 1-((_root[menu_Array[j]]._y-20)-_root.point._y)/(_root[menu_Array[j]].ori_hei*2.5-20);
if (_root["percent_y"+j]>=1) {
_root["percent_y"+j] = 1;
}
_root["percent_xy"+j] = _root["percent_x"+j]*_root["percent_y"+j];
_root[menu_Array[j]]._width = _root["percent_xy"+j]*60+40;
_root[menu_Array[j]]._height = _root["percent_xy"+j]*60+40;
} else if (huanchong) {
_root[menu_Array[j]]._width -= (_root[menu_Array[j]]._width-40)/5;
_root[menu_Array[j]]._height -= (_root[menu_Array[j]]._height-40)/5;
} else {
_root[menu_Array[j]]._width = 40;
_root[menu_Array[j]]._height = 40;
}
//-------------------菜单提示TXT----------------
_root[menu_Array[j]].onRollOver = function() {
this.menu_name = true;
this.swapDepths(_root.getNextHighestDepth());
};
_root[menu_Array[j]].onRollOut = function() {
this.menu_name = false;
};
_root[menu_Array[j]].onPress = function() {
        trace(menu_URL[this.id]);
    };
if (_root[menu_Array[j]].menu_name) {
_root.createTextField(menu_Array[j]+"txt",_root.getNextHighestDepth(),-10,-40,50,30);
_root[menu_Array[j]+"txt"].bold = true;
_root[menu_Array[j]+"txt"].text = menu_Array[j];
_root[menu_Array[j]+"txt"]._xscale = _root[menu_Array[j]+"txt"]._yscale=150;
_root[menu_Array[j]+"txt"].textColor = 0x000000;
_root[menu_Array[j]+"txt"]._x = _root[menu_Array[j]]._x-_root[menu_Array[j]+"txt"]._width/2;
_root[menu_Array[j]+"txt"]._y = Stage.height-_root[menu_Array[j]]._height;
_root[menu_Array[j]+"txt"].selectable = false;
} else {
_root[menu_Array[j]+"txt"].removeTextField();
}
}
_root[menu_Array[0]]._x = _root.setoff._x-_root.setoff._width/2+_root[menu_Array[0]]._width/2+10;
for (var j:Number = 1; j<=menu_Array.length-1; j++) {
_root[menu_Array[j]]._x = _root[menu_Array[j-1]]._x+_root[menu_Array[j-1]]._width/2+_root[menu_Array[j]]._width/2;
}
},10);
在改动图标位置的地方,我注释了

TOP

呵呵
可以了
非常感谢楼上啊
谢谢~~~~~~~~~~~

TOP

_root[menu_Array[j]].mc._y = -_root[menu_Array[j]]._height-20;//这里可以改动图标Y的坐标,上移20

这行代码好象只是移动图片的位置
在哪里设置把响应的热区也往上移动

TOP