2014-11-14 69 views
0

C:\Users\Lab3project\MainDocument.as, Line 103, Column 7 1013: The private attribute may be used only on class property definitions.的Flash AS3錯誤:1013:私有屬性只能在類的屬性定義

相關的代碼行中:

package { 
    //these are flash built-in classes 
    import flash.display.MovieClip; 
    import flash.events.TimerEvent; 
    import flash.utils.Timer; 
    import flash.events.Event; 
    //Our own custom class 
    import MainTimer; 

    public class MainDocument extends MovieClip{ 

     private var gameTimer:MainTimer; 
     private var thePlayer:Player; 
     private var theEnemy:Enemy; 
     private var maxEnemies: int = 3; 
     private var e:int = 0; 
     private var childrenOnStage:int; 

     public function MainDocument() { 
      // constructor code 
      trace("the main document is alive"); 

      // new instance MainTimer class 
      gameTimer = new MainTimer(); 

      // must add it to the stage 
      addChild(gameTimer); 
      //adjust its postion on stage 
      gameTimer.x = 20; 
      gameTimer.y = 20; 

      //add the player 
      thePlayer = new Player(); 
      addChild(thePlayer); 
      // adjust its postion on the stage 
      thePlayer.x = stage.stageWidth * 0.5; 
      //assign the name property 
       thePlayer.name = "player"; 

       while(e < maxEnemies){ 
        createEnemy(); 
        e++; 
       } //end while 

       //Update this variable every time a child is added to the stage 
        childrenOnStage = this.numChildren 

       // Add event listener to control timing of main game loop 
        addEventListener(Event.ENTER_FRAME,mainGameLoop); 

      }//end function MainDocument 

      private function createEnemy():void{ 
       trace("create enemy"); 
       theEnemy = new Enemy(); 
       addChild(theEnemy); 
       //Place in a random spot on stage 
       theEnemy.x = (Match.random() * stage.stageWidth); 
       theEnemy.y = 0; 

       //assign the name property 
        theEnemy.name = "enemy"; 

       //Update this variable every time a child is added to the stage 
        childrenOnStage = this.numChildren 
       } //end function createEnemy 

      //the main loop for the game 
      private function mainGameLoop(event:Event): void{ 

       checkForGameReset(); 

       processCollisions(); 

       scrollStage(); 

      } // end functiom mainGameLoop 
       private function checkForGameReset():void{ 
        //define conditions 
       } //end function checkForGameReset 

       private function processCollisions():void{ 
        //set up the main loop to look through all collidale objects on stage 
        for(var c:int;c < childOnStage;c++){ 
         //trace ("Child on stage c= " + c + 
         //test for a player of enemy child on stage 
      if (getChildAt(c).name == "player" || getChildAt(c).name == "enemy"){ 
       //see if object is touching the game stage 
       if(theGameStage.hitTestPoint(getChildAt(c).x, getChildAt(c).y,true)){ 
        //while it is still touching the game stage 
        while(theGameStage.hitTestPoint(getChildAt(c).x, getChildAt(c).y,true)==true){ 
         //called from CollisionObject class,so force the connection 
         CollisionObject(getChildAt(c)).incrementUpward(); 
        if(theGameStage.hitTestPoint(getChildAt(c).x, getChildAt(c).y,true)==false){ 
        }CollisionObject(getChildAt(c)).keepOnBoundary(); //make it stick 
        } // end if 
        } // end while 
       } //end if touching 
       } //end if player or enemy 
       } //end for loop 
      } //end function processCollisions 

The lines of code concerned: is here where im getting the error 
    private function scrollStage(): void 
    { 
     // figure out logic 
    } 
    // end function scrollStage 


      //add the enemy for testing 
      theEnemy = new Enemy(); 
      addChild(theEnemy); 
      // adjust its postion on the stage 
      theEnemy.x = stage.stageWidth * 0.5; 
      theEnemy.y = 200; 



     } // end public function MainDocument 

    } // end public class 


} // end package 

後,我有改變的代碼,它就會說我有一個額外的最後的角色,但最後我必須擁有的角色。

+1

如果可以,請發佈您的整個MainDocument.as。很可能你沒有把方法顯示在類聲明中(或者以其他方式嵌套它)。 – BadFeelingAboutThis 2014-11-14 22:43:02

回答

3

這樣的問題通常是由於語法上的輕微錯字而發生的。也許你不小心在另一個函數中聲明瞭你的私有函數?

public function doSomething() { 
    //a whole bunch of stuff 
//then we forget to close the function with a brace "}" 

private function scrollStage() { 
    //but we're still defining doSomething! Throw error! 
} 

去尋找這樣的錯誤,並希望你能找到問題。