Flash游戏中的Actionscript错误#1056

时间:2012-11-19 06:34:26

标签: actionscript-3 flash

我有一个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()

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

1 个答案:

答案 0 :(得分:0)

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

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

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