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

Flash动画制作
用FLASH MX制作动画卡通人物(1)-人物素材的准备与处理
最强大的Flash反编译工具(三)
DW MX 2004的Flash动画元素 下
Flash制作空战游戏(三)
Flash MX 2004视频文件轻松播
用FLASH MX制作动画卡通人物(4)-让人物动起来
简单实用的Flash技巧心得
妙用Flash遮罩层实现水流效果
Flash MV音乐和字幕的制作(上)
最强大的Flash反编译工具(二)
Flash制作空战游戏(一)
动态生成Flash网页
Flash层的运用(五)
Flash MX 视频导入功能详解(2)
Flash MX 视频导入功能详解(3)
Flash MX 视频导入功能详解(4)
利用Flash MX模板制作XML动态菜单(2)
FW MX和Flash MX的亲密合作(4)
Flash5键盘鼠标应用(一)
Flash5键盘鼠标应用(三)

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-22   浏览: 123 ::
收藏到网摘: 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