注册 | 登录 | 设为首页 | 加入收藏
您当前的位置:飞翔学院-IT中国 → 图形图像flash → 文章内容

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

作者:佚名 来源:不详 发布时间:2007-9-28 20:12:40

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


  • 打印文档
  • 推荐好友
  • 返回顶部
  • 增大字体
  • 减少字体
关于本站 | 工作机会 | 合作网站 | 广告服务 | 市场合作| 联系我们 | 抽奖活动
版权所有: 武汉威俊科技有限公司 Copyright 2005-2007 www.ITCNW.COM All rights reserved