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

Flash动画制作
我是大导演 MTV创作速成教程
二合一按钮的制作
[DIY]这种相册你有吗?
教你一招绝的!把Flash动画转换成VCD视频
使用Flash MX的3个小技巧
Flash课件一网打尽
Flash Player 7 安全策略解析
FlashMX特效之扩散与挤压
Flash MX 2004 体验之旅
Flash使用技巧--用Flash制作拖拉式菜单
Flash使用技巧--用Flash制作转动的地球仪
Flash使用技巧--用Flash 5制作Winamp光谱柱的效果
Flash使用技巧--用Flash制作落地有声的瓶子
Flash使用技巧--用Flash 5巧做“弹出”效果菜单
Flash使用技巧--用Flash制作即指即现的广告条
用大师级软件MixFX轻松打造专业FLASH
用Flash MX快速制作沟通留言程序
用Flash制作动感效果的网页链接提示框
巧妙运用Flash MX 2004制作“拖曳配对题”
用Flash MX制作精彩的粉荷清波动画特效一例

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


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