当前位置: 首页 > 图文教程 > Flash动画 > Flash动画制作 > Flash初级教程:介绍两种按钮控制小球左右滚动的写法

Flash动画制作
MM对Flash MX 2004的最新改进
FlashMX经典实例(9)
Flash 动作脚本之:了解Action Script2.0 (3)
Flash 动作脚本之:资料速查(2)
Flash 动作脚本之:资料速查(6)
Flash 动作脚本之:资料速查(7)
Flash 动作脚本之:资料速查(8)
Flash 动作脚本之:资料速查(15)
Flash 动作脚本之:资料速查(17)
Flash MX pro的历史面板(3)
Class结构教程
条件循环的使用
波动方程的应用
AS的基本代码解释(1)
Flash MX 编程深层次应用-第三方软件(6)
Flash MX Pro 2004新模板应用(2)
Flash手绘一副帅气眼镜(2)
Flash手绘一副帅气眼镜(3)
Flash手绘一副帅气眼镜(4)
Flash MX 2004 模拟出打字效果的制作方法

Flash动画制作 中的 Flash初级教程:介绍两种按钮控制小球左右滚动的写法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-22   浏览: 129 ::
收藏到网摘: n/a

[前言]
高手莫看,给初学者。
[步骤]
第一步:创建影片剪辑元件,画个小球,拖到主场景中,实例名为_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() {
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://bbs.ruanchen.com/hread-117818-1-1.html