按钮控制小球左右滚动的两种写法(基础篇)
作者:qinz 类型:闪吧BBS 来源:闪吧论坛
[前言]
高手莫看,给初学者。
[步骤]
第一步:创建影片剪辑元件,画个小球,拖到主场景中,实例名为_mc
第二步:创建按钮元件,画一个按钮,拖到主场景中,实例名为_btn
第三步:在主场景中的第一帧上写代码:
进入论坛和作者一起讨论学习:http://space.flash8.net/bbs/thread-342049-1-1.html
浏览作者的个人空间:http://space.flash8.net/space/?401869
高手莫看,给初学者。
[步骤]
第一步:创建影片剪辑元件,画个小球,拖到主场景中,实例名为_mc
第二步:创建按钮元件,画一个按钮,拖到主场景中,实例名为_btn
第三步:在主场景中的第一帧上写代码:
var i:Number = 0;
_btn.onRelease = function() {
i++;
if (i%2 == 1) {
_mc.onEnterFrame = function() {
this._x -= 10;
if (this._x<=-20) {
this._x = 570;
}
};
}
if (i%2 == 0) {
_mc.onEnterFrame = function() {
_mc._x += 10;
if (this._x>=570) {
this._x = -20;
}
};
}
};
—————————————————或者———————————————————_btn.onRelease = function() {
i++;
if (i%2 == 1) {
_mc.onEnterFrame = function() {
this._x -= 10;
if (this._x<=-20) {
this._x = 570;
}
};
}
if (i%2 == 0) {
_mc.onEnterFrame = function() {
_mc._x += 10;
if (this._x>=570) {
this._x = -20;
}
};
}
};
_btn.onRelease = function() {
this.id = !this.id;
if (this.id) {
_mc.onEnterFrame = function() {
this._x -= 10;
if (this._x <= -20) {
this._x = 570;
}
};
}
if (!this.id) {
_mc.onEnterFrame = function() {
_mc._x += 10;
if (this._x >= 570) {
this._x = -20;
}
};
}
};
看看效果:this.id = !this.id;
if (this.id) {
_mc.onEnterFrame = function() {
this._x -= 10;
if (this._x <= -20) {
this._x = 570;
}
};
}
if (!this.id) {
_mc.onEnterFrame = function() {
_mc._x += 10;
if (this._x >= 570) {
this._x = -20;
}
};
}
};
进入论坛和作者一起讨论学习:http://space.flash8.net/bbs/thread-342049-1-1.html
浏览作者的个人空间:http://space.flash8.net/space/?401869
责任编辑:silvia 时间:2007年9月18日
- 上一篇:
- 网页制作中经常用到的六则代码技巧
- 下一篇:
- Photoshop打造绚丽夜景
- 没有相关教材
- 最近更新
