Disabled按钮的制作方法
类别: Flash教程
效果浏览:
在一些特定应用中,我们需要用到按钮的Disabled状态.下面我们就来制作一个这样的效果.
1.首先,在场景中新建一个MC(影片剪辑MovieClip),在此MC中绘制一个图形,把线条和填充颜色分别转换为MC,如图1:
(图1);
2.完成后拖到场景中,复制一个,并调整方向,分别取实例名为”arrowPrev””arrowNext”,如图2:
(图2)
3.在场景中绘制一个动态文本,命名变量名为”currentPage”,用于显示当前页数;
4.界面工作完毕,下面新建一图层,命名为AS,按F9打开动作面板,输入/复制下面的代码:
//初始化页面总数
pageNum = 5;
//初始化按钮
arrowPrev.enabled = false;
arrowNext.enabled = true;
borderColor = new Color(arrowPrev.border);
borderColor.setRGB("0x999999");
fillColor = new Color(arrowPrev.fill);
fillColor.setRGB("0xcccccc");
//上一页按钮
arrowPrev.onRollOver = function() {
borderColor = new Color(this.border);
borderColor.setRGB("0xff6600");
fillColor = new Color(this.fill);
fillColor.setRGB("0xFFEBD7");
};
arrowPrev.onRollOut = function() {
borderColor = new Color(this.border);
borderColor.setRGB("0x339966");
fillColor = new Color(this.fill);
fillColor.setRGB("0xD2F0E1");
};
arrowPrev.onRelease = function() {
arrowNext.enabled = true;
borderColor = new Color(arrowNext.border);
borderColor.setRGB("0x339966");
fillColor = new Color(arrowNext.fill);
fillColor.setRGB("0xD2F0E1");
if (currentPage>1) {
currentPage = parseInt(currentPage)-1;
} else {
this.enabled = false;
borderColor = new Color(this.border);
borderColor.setRGB("0x999999");
fillColor = new Color(this.fill);
fillColor.setRGB("0xcccccc");
}
};
//下一页按钮
arrowNext.onRollOver = function() {
borderColor = new Color(this.border);
borderColor.setRGB("0xff6600");
fillColor = new Color(this.fill);
fillColor.setRGB("0xFFEBD7");
};
arrowNext.onRollOut = function() {
borderColor = new Color(this.border);
borderColor.setRGB("0x339966");
fillColor = new Color(this.fill);
fillColor.setRGB("0xD2F0E1");
};
arrowNext.onRelease = function() {
arrowPrev.enabled = true;
borderColor = new Color(arrowPrev.border);
borderColor.setRGB("0x339966");
fillColor = new Color(arrowPrev.fill);
fillColor.setRGB("0xD2F0E1");
if (currentPage<pageNum) {
currentPage = parseInt(currentPage)+1;
} else {
this.enabled = false;
borderColor = new Color(this.border);
borderColor.setRGB("0x999999");
fillColor = new Color(this.fill);
fillColor.setRGB("0xcccccc");
}
};
//拖动场景
drag.onMouseDown=function(){
if(this.hitTest(_xmouse,_ymouse,true)) startDrag(_root,false);
}
drag.onMouseUp=function(){
stopDrag();;
}
pageNum = 5;
//初始化按钮
arrowPrev.enabled = false;
arrowNext.enabled = true;
borderColor = new Color(arrowPrev.border);
borderColor.setRGB("0x999999");
fillColor = new Color(arrowPrev.fill);
fillColor.setRGB("0xcccccc");
//上一页按钮
arrowPrev.onRollOver = function() {
borderColor = new Color(this.border);
borderColor.setRGB("0xff6600");
fillColor = new Color(this.fill);
fillColor.setRGB("0xFFEBD7");
};
arrowPrev.onRollOut = function() {
borderColor = new Color(this.border);
borderColor.setRGB("0x339966");
fillColor = new Color(this.fill);
fillColor.setRGB("0xD2F0E1");
};
arrowPrev.onRelease = function() {
arrowNext.enabled = true;
borderColor = new Color(arrowNext.border);
borderColor.setRGB("0x339966");
fillColor = new Color(arrowNext.fill);
fillColor.setRGB("0xD2F0E1");
if (currentPage>1) {
currentPage = parseInt(currentPage)-1;
} else {
this.enabled = false;
borderColor = new Color(this.border);
borderColor.setRGB("0x999999");
fillColor = new Color(this.fill);
fillColor.setRGB("0xcccccc");
}
};
//下一页按钮
arrowNext.onRollOver = function() {
borderColor = new Color(this.border);
borderColor.setRGB("0xff6600");
fillColor = new Color(this.fill);
fillColor.setRGB("0xFFEBD7");
};
arrowNext.onRollOut = function() {
borderColor = new Color(this.border);
borderColor.setRGB("0x339966");
fillColor = new Color(this.fill);
fillColor.setRGB("0xD2F0E1");
};
arrowNext.onRelease = function() {
arrowPrev.enabled = true;
borderColor = new Color(arrowPrev.border);
borderColor.setRGB("0x339966");
fillColor = new Color(arrowPrev.fill);
fillColor.setRGB("0xD2F0E1");
if (currentPage<pageNum) {
currentPage = parseInt(currentPage)+1;
} else {
this.enabled = false;
borderColor = new Color(this.border);
borderColor.setRGB("0x999999");
fillColor = new Color(this.fill);
fillColor.setRGB("0xcccccc");
}
};
//拖动场景
drag.onMouseDown=function(){
if(this.hitTest(_xmouse,_ymouse,true)) startDrag(_root,false);
}
drag.onMouseUp=function(){
stopDrag();;
}
为什么每次都要建一个颜色对象.事先建好.不是省去很多冗余.而且那个按钮到了第一页和第五页后必须再按一下才会无效..这也算个BUG吧..一同修改过.效果如下: 我觉的这样的效果用时间轴动画实现更为简单.
//初始化页面总数
pageNum = 5;
//初始化按钮
arrowPrev.enabled = false;
arrowNext.enabled = true;
borderColor = new Color(arrowPrev.border);
fillColor = new Color(arrowPrev.fill);
rgbset(borderColor, 0x999999, fillColor, 0xcccccc);
borderColornext = new Color(arrowNext.border);
fillColornext = new Color(arrowNext.fill);
//上一页按钮
arrowPrev.onRollOver = function() {
rgbset(borderColor, 0xff6600, fillColor, 0xFFEBD7);
};
arrowPrev.onRollOut = function() {
rgbset(borderColor, 0x339966, fillColor, 0xD2F0E1);
};
arrowPrev.onRelease = function() {
arrowNext.enabled = true;
rgbset(borderColornext, 0x339966, fillColornext, 0xD2F0E1);
if (currentPage>2) {
currentPage = parseInt(currentPage)-1;
} else {
currentPage = parseInt(currentPage)-1;
this.enabled = false;
rgbset(borderColor, 0x999999, fillColor, 0xcccccc);
}
};
//下一页按钮
arrowNext.onRollOver = function() {
rgbset(borderColornext, 0xff6600, fillColornext, 0xFFEBD7);
};
arrowNext.onRollOut = function() {
rgbset(borderColornext, 0x339966, fillColornext, 0xD2F0E1);
};
arrowNext.onRelease = function() {
arrowPrev.enabled = true;
rgbset(borderColor, 0x339966, fillColor, 0xD2F0E1);
if (currentPage<pageNum-1) {
currentPage = parseInt(currentPage)+1;
} else {
currentPage = parseInt(currentPage)+1;
this.enabled = false;
rgbset(borderColornext, 0x999999, fillColornext, 0xcccccc);
}
};
//拖动场景
drag.onMouseDown = function() {
if (this.hitTest(_xmouse, _ymouse, true)) {
startDrag(_root);
}
};
drag.onMouseUp = function() {
stopDrag();
};
function rgbset(rgbobj1, rgb1, rgbobj2, rgb2) {
rgbobj1.setRGB(rgb1);
rgbobj2.setRGB(rgb2);
}
pageNum = 5;
//初始化按钮
arrowPrev.enabled = false;
arrowNext.enabled = true;
borderColor = new Color(arrowPrev.border);
fillColor = new Color(arrowPrev.fill);
rgbset(borderColor, 0x999999, fillColor, 0xcccccc);
borderColornext = new Color(arrowNext.border);
fillColornext = new Color(arrowNext.fill);
//上一页按钮
arrowPrev.onRollOver = function() {
rgbset(borderColor, 0xff6600, fillColor, 0xFFEBD7);
};
arrowPrev.onRollOut = function() {
rgbset(borderColor, 0x339966, fillColor, 0xD2F0E1);
};
arrowPrev.onRelease = function() {
arrowNext.enabled = true;
rgbset(borderColornext, 0x339966, fillColornext, 0xD2F0E1);
if (currentPage>2) {
currentPage = parseInt(currentPage)-1;
} else {
currentPage = parseInt(currentPage)-1;
this.enabled = false;
rgbset(borderColor, 0x999999, fillColor, 0xcccccc);
}
};
//下一页按钮
arrowNext.onRollOver = function() {
rgbset(borderColornext, 0xff6600, fillColornext, 0xFFEBD7);
};
arrowNext.onRollOut = function() {
rgbset(borderColornext, 0x339966, fillColornext, 0xD2F0E1);
};
arrowNext.onRelease = function() {
arrowPrev.enabled = true;
rgbset(borderColor, 0x339966, fillColor, 0xD2F0E1);
if (currentPage<pageNum-1) {
currentPage = parseInt(currentPage)+1;
} else {
currentPage = parseInt(currentPage)+1;
this.enabled = false;
rgbset(borderColornext, 0x999999, fillColornext, 0xcccccc);
}
};
//拖动场景
drag.onMouseDown = function() {
if (this.hitTest(_xmouse, _ymouse, true)) {
startDrag(_root);
}
};
drag.onMouseUp = function() {
stopDrag();
};
function rgbset(rgbobj1, rgb1, rgbobj2, rgb2) {
rgbobj1.setRGB(rgb1);
rgbobj2.setRGB(rgb2);
}
- 上一篇: FLASH结合ASP数据库的应用
- 下一篇: Flash AS基础精典教程
-= 资 源 教 程 =-
文 章 搜 索