暂存AS代码

博客展示了一段AS代码,定义了自定义函数Dat,用于实现图片的拖动、扩大和缩小操作。拖动时限制图片不超出边框范围,扩大和缩小操作有相应的判断条件,且在释放按钮时会删除相关的帧事件。

小角色让看看这些AS代码,暂存:

//场景宽度
var stag_x = Stage.width;
//场景高度
var Stag_y = Stage.height;
//自定义函数
function Dat(move, bot_D, bot_K, sped_x) {
 //拖动。说明:其中的四个判断用于限制图片不得超出边框范围。
 move.onPress = function() {
  this.onEnterFrame = function() {
   //向右拖的判断
   if (this._x>=0) {
    this._x = 0;
   } else if (this._x<=(Stag_y-this._width)) {
    //向左拖的判断 
    this._x = stag_x-this._width;
   }
   if (this._y>=0) {
    //向下拖的判断 
    this._y = 0;
   } else if (this._y<=Stag_y-this._height) {
    //向上拖的判断 
    this._y = Stag_y-this._height;
   }
  };
  this.startDrag();
 };
 //停止拖动 
 move.onRelease = function() {
  this.stopDrag();
 };
 //同上 
 move.onReleaseOutside = function() {
  this.stopDrag();
 };
 //扩大按钮的代码。其中的判断用于在缩小按钮不可用时恢复其可用。
 bot_D.onPress = function() {
  if (suoxiao.enabled == false) {
   suoxiao.enabled = true;
  }
  move.onEnterFrame = function() {
   this._yscale = this._xscale += sped_x;
  };
 };
 bot_D.onRelease = function() {
  delete move.onEnterFrame;
 };
 //缩小按钮的代码,其中加的限制条件是为了在缩小时防止背景漏出。
 //当达到最小的范围时,缩小按钮不可用。
 bot_K.onPress = function() {
  move.onEnterFrame = function() {
   if (this._width<=(Stage.width+Math.abs(this._x)) || this._height<=(Stage.height+Math.abs(this._y))) {
    bot_K.enabled = false;
   } else {
    this._yscale = this._xscale -= sped_x;
   }
  };
 };
 bot_K.onRelease = function() {
  delete pic.onEnterFrame;
 };
}
Dat(pic, kuoda, suoxiao, 1, 1);

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值