【问题标题】:Converting AS2 to AS3将 AS2 转换为 AS3
【发布时间】:2012-01-24 17:25:21
【问题描述】:

我是 Flash AS3 的新手,我在网上看到过这段代码,但它是用 AS2 编码的,任何人都可以帮助我。

onClipEvent (enterFrame)
{
   distance = _root.enemy._x - _root.player._x;
   if (distance < 100 && distance > -100 && _root.enemyTimer == 0)
   {
      a = int(Math.random() * 100);
      if (a >= 0 && a < 60)
      {
          _root.enemy.gotoAndStop('attack1');
          _root.healthbar.gotoAndStop(_root.healthbar._currentframe -= 5);
      }
      else if (a >= 60 && a <= 100)
      {
          _root.enemy.gotoAndStop('attack2');
          _root.healthbar.gotoAndStop(_root.healthbar._currentframe -= 8);
      }
   }
   if (distance < 160 && distance > 100)
   {
          this._xscale = _root.eScale;
          _x -= 2;
   }
   if (distance > -160 && distance < -100)
   {
         this._xscale = -_root.eScale;
         _x += 2;
   }
}

tnx 提前我会用这个作为参考。

【问题讨论】:

  • 您需要进行一些小的更改,请查看as2 to as3 migration guide(其中很多在线)以开始使用。顺便说一句,这一行:a = int(Math.random() * 100); 看起来不像 as2,在 as3 中添加了 int

标签: actionscript-3 actionscript-2


【解决方案1】:
this.addEventListener(Event.ENTER_FRAME, functionName);

function functionName(e:Event):void
{
    var distance:Number = this.enemy.x - this.player.x;
    if (distance < 100 && distance > -100 && this.enemyTimer == 0)
    {
        var a:int = int(Math.random() * 100);
        if (a >= 0 && a < 60)
        {
            this.enemy.gotoAndStop('attack1');
            this.healthbar.gotoAndStop(this.healthbar.currentFrame -= 5);
        }
        else if (a >= 60 && a <= 100)
        {
             this.enemy.gotoAndStop('attack2');
             this.healthbar.gotoAndStop(this.healthbar.currentFrame -= 8);
        }
    }
    if (distance < 160 && distance > 100)
    {
        this.scaleX = this.eScale;
        this.x -= 2;
    }
    if (distance > -160 && distance < -100)
    {
        this.scaleX = -this.eScale;
        this.x += 2;
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-14
    • 2013-07-18
    • 2023-04-07
    • 1970-01-01
    • 2017-07-28
    • 2018-04-19
    相关资源
    最近更新 更多