0

我有一个 Flash 游戏,它在下面的代码中显示错误

private function onAddingTimer(event:TimerEvent) : void
       {
           var _loc_2:int = 0;
           var _loc_3:MovieClip = null;
           var _loc_4:MovieClip = null;
           var _loc_5:String = this;
           var _loc_6:* = this.timerAddCounter + 1;
           _loc_5.timerAddCounter = _loc_6;
           this.bonusIntervalDiff = int(this.levelData[this.level].enemyCount / this.levelData[this.level].bonusCount);
           if (this.timerAddCounter >= this.levelData[this.level].createDelay)
           {
               var _loc_5:String = this;
               var _loc_6:* = this.timerAddCount + 1;
               _loc_5.timerAddCount = _loc_6;
               if (int(this.timerAddCount % this.bonusIntervalDiff) == 0)
               {
                   _loc_2 = this.rangeRandom(0, this.LIFE_CLASSES.length);
                   trace("Ran:: " + _loc_2);
                   _loc_3 = new this.LIFE_CLASSES[_loc_2].className() as MovieClip;
                   this.spLifeGround.addChild(_loc_3);
                   _loc_3.y = 500;
                   this.previousX = this.rangeRandomWithPreviousDifference(100, 700, 210, this.previousX);
                   _loc_3.x = this.previousX;
                   this.lifes.push({mc:_loc_3, score:this.LIFE_CLASSES[_loc_2].score, cls:this.LIFE_CLASSES[_loc_2].className});
               }
               else
               {
                   _loc_4 = new this.EMENY_CLASSES[this.rangeRandom(0, this.EMENY_CLASSES.length)] as MovieClip;
                   this.spEnemyGround.addChild(_loc_4);
                   _loc_4.y = 450;
                   this.previousX = this.rangeRandomWithPreviousDifference(75, 725, 210, this.previousX);
                   _loc_4.x = this.previousX;
                   this.enemys.push(_loc_4);
               }
               this.timerAddCounter = 0;
           }
           return;
       }// end function

来自控制台的错误是

ReferenceError:错误 #1056:无法在字符串上创建属性 timerAddCounter。在 JuegoGame/onAddingTimer() 在 flash.utils::Timer/_timerDispatch() 在 flash.utils::Timer/tick()

有谁知道,为什么它不能正常工作。

4

1 回答 1

0

因为StringActionscript 3 中的对象不支持动态添加变量。您的代码正在尝试将属性添加timerAddCounterString实例。

var _loc_5:String = this;
...
_loc_5.timerAddCounter = _loc_6;

_loc_5必须是动态对象,或具有 setter 的对象timeAddCounter

于 2012-11-19T06:37:10.873 回答