2012-01-24 21 views
0

私はFlash AS3を初めて使用しています。このコードはオンラインで見ましたが、AS2でコード化されている人は誰でも助けてくれます。AS2からAS3への変換

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; 
    } 
} 

事前にこれを参考にしています。

+0

ご質問はありますか? – Kodiak

+1

マイナーな変更が必要な場合は、[as2からas3への移行ガイド](http://www.mandalatv.net/fcny/)(オンラインで十分)を見て開始してください。 btw、この行: 'a = int(Math.random()* 100);'はas2のようには見えませんが、as3にintが追加されました –

答えて

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; 
    } 
} 
関連する問題