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

Flash动画制作
flash人物侧面绘画
用Flash 绘制世界杯会标
Flash中表现粗细变化笔触效果
Flash制作可爱时钟
标准的loading制作方法
人物造型
在Flash中使用位图的技巧
Flash制作特酷的图片遮照特效动画
Flash3d效果实例--水晶球
Flash MX Pro 2004播放视频文件
FLASH特效—有趣的手动哈哈镜
创建FLASH 塑料质感按钮
人物走路动作分解
Flash中简单跟踪弹的算法
FLASH实用技巧之太阳系制造
用Flash制作“拖曳配对题”
FlashMX2004精彩特效:网格式复制
FlashMX2004精彩特效之阴影
进度条 - 步骤教程
FLASH2004实例 : AS控制的扇子制作方法

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


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