2013-04-06 56 views
0

我有10個錯誤(1120)與未定義屬性的訪問相關聯。 onEnterFrame,onClick,onLeftClick,MouseUp,onUpClick,MouseUp,onDownClick,MouseUp,onRightClick和MouseUp。(AS3)Fixing Frogger遊戲ActionScript 3

的錯誤正在從閱讀進度氟里昂線拋出58至73

package 
{ 
    import flash.display.MovieClip; 
    import flash.events.KeyboardEvent; 
    import flash.ui.Keyboard; 
    import flash.events.Event; 
    import flash.events.MouseEvent; 


    public class FrogKatta extends MovieClip 
    { 
     // Create instances of library symbols 
     var car1:Car = new Car(); 
     var car2:Car = new Car(); 
     var truck1:Truck = new Truck(); 
     var truck2:Truck = new Truck(); 
     var frog:Frog = new Frog(); 
     var FinishLine:finishLine = new finishLine(); 
     var HealthBar:healthBar = new healthBar(); 
     var vx:int = 0; 
     var vy:int = 0; 

     var hit:Boolean = false; 
     var carStart:Boolean = false; 
     var truckStart:Boolean = false; 



     public function frogKatta() 
     { 
      frog.x = 230; 
      frog.y = 375; 

      truck1.x = 545; 
      truck1.y = 230; 

      truck2.x = 560; 
      truck2.y = 235; 

      car1.x = 550; 
      car1.y = 78; 

      car2.x = 560; 
      car2.y = 80; 

      // add created instances to stage 
      addChild(frog); 
      addChild(truck1); 
      addChild(truck2); 
      addChild(car1); 
      addChild(car2); 
      // * PROBLEM WITH STAGE.ADDEVENTLISTENER 
      // Add event listener for keyboard 

// PROBLEM STARTS HERE *********** 


      stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown); 
      stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp); 


      addEventListener(Event.ENTER_FRAME, onEnterFrame); 

      // Add Event for mouse click 
      stage.addEventListener(MouseEvent.CLICK, onClick); 
      // creating instance of onClick from the MouseEvent.CLICK 
      //Keyboard 
      left.addEventListener(MouseEvent.MOUSE_DOWN, onLeftClick); 
      // to move 
      left.addEventListener(MouseEvent.MOUSE_UP, MouseUp); 
      // to stop 
      up.addEventListener(MouseEvent.MOUSE_DOWN, onUpClick); 
      up.addEventListener(MouseEvent.MOUSE_UP, MouseUp); 
      down.addEventListener(MouseEvent.MOUSE_DOWN, onDownClick); 
      down.addEventListener(MouseEvent.MOUSE_UP, MouseUp); 
      right.addEventListener(MouseEvent.MOUSE_DOWN, onRightClick); 
      right.addEventListener(MouseEvent.MOUSE_UP, MouseUp); 

// PROBLEM ENDS HERE**** 


      // Keyboard functionality 
      function onKeyDown(event:KeyboardEvent):void 
      { 
       if (event.keyCode == Keyboard.LEFT) 
       { 
        vx = -5; 
        frog.play(); 
       } 
       else if (event.keyCode == Keyboard.RIGHT) 
       { 
        vx = 5; 
        frog.play(); 
       } 
       else if (event.keyCode == Keyboard.DOWN) 
       { 
        vy = 5; 
        frog.play(); 
       } 
       else if (event.keyCode == Keyboard.UP) 
       { 
        vy = -5; 
        frog.play(); 
       } 
      } 

      // Keyboard again to stop 
      function onKeyUp(event:KeyboardEvent):void 
      { 
       if (event.keyCode == Keyboard.LEFT || event.keyCode == Keyboard.RIGHT) 
       { 
        vx = 0; 
        frog.stop(); 
       } 
       else if (event.keyCode == Keyboard.DOWN || event.keyCode == Keyboard.UP) 
       { 
        vy = 0; 
        frog.stop(); 
       } 

       // Clicking Functionality 
       function MouseUp(event:MouseEvent):void 
       { 
        vy = 0; 
        vx = 0; 
        frog.stop(); 
       } 
       // on"librarybutton name left" Click 
       function onLeftClick(event:MouseEvent):void 
       { 
        vx = -5; 
        frog.play(); 
       } 
       function onUpClick(event:MouseEvent):void 
       { 
        vy = -5; 
        frog.play(); 
       } 
       function onDownClick(event:MouseEvent):void 
       { 
        vy = 5; 
        frog.play(); 
       } 
       function onRightClick(event:MouseEvent):void 
       { 
        vx = 5; 
        frog.play(); 
       } 


       // on enter frame 
       function onEnterFrame(event:Event):void 
       { 
        frog.x += vx; 
        frog.y += vy; 

        truck1.x += -10; 
        car1.x += -20; 


        //Car1 & 2 SCREEN WRAPPING 
        if (car1.x <= -400) 
        { 
         car1.x = 550; 
        } 
        // If car 1 leaves screen add car to other side of the screen 

        if (car2.x <= -400) 
        { 
         car2.x = 550; 
        } 

        if (car1.x <= 135) 
        { 
         carStart = true; 
        } 
        // Screen wrap so if car is less than or equal to 135 in distance add another car 

        if (carStart) 
        { 
         car2.x += -15; 
        } 

        //Truck1 & 2 
        if (truck1.x <= -400) 
        { 
         truck1.x = 550; 
        } 

        if (truck2.x <= -400) 
        { 
         truck2.x = 550; 
        } 


        if (truck1.x <= 135) 
        { 
         truckStart = true; 

        } 

        if (truckStart) 
        { 
         truck2.x += -10; 

        } 
        if (frog.hitTestObject(truck1) || frog.hitTestObject(truck2) || frog.hitTestObject(car1) || frog.hitTestObject(car2)) 
        { 
         frog.y += 10; 
         hit = true; 

        } 
        if (hit) 
        { 
         if (HealthBar.width < 10) 
         { 
          HealthBar.width = 0; 
         } 
         else 
         { 
          HealthBar.width -= 10; 
         } 
        } 

        if (HealthBar.width < 1) 
        { 
         //S.O.P you lose); 
        } 




        if (frog.hitTestObject(FinishLine)) 
        { 

         removeChild(frog); 
         removeChild(FinishLine); 
         removeChild(car1); 
         removeChild(car2); 
         removeChild(truck1); 
         removeChild(truck2); 
         // addchild of you winning 

        } 

       } 
      } 

     } 
    } 
} 

回答

0

你有一個括號的問題,我相信。

你需要在你的onKeyDown函數之前有一個'}'。

檢查所有的括號,在插入我告訴過的那個之後,你可能還會在文件末尾添加一個括號。

這些行是一個問題,因爲上/下/左/右不存在於您的代碼中。如果它們是階段實例,它們很可能不會被命名,因此您的代碼將無法使用它們。如果是這種情況,請通過屬性面板命名實例。

left.addEventListener(MouseEvent.MOUSE_DOWN, onLeftClick); 
    // to move 
    left.addEventListener(MouseEvent.MOUSE_UP, MouseUp); 
    // to stop 
    up.addEventListener(MouseEvent.MOUSE_DOWN, onUpClick); 
    up.addEventListener(MouseEvent.MOUSE_UP, MouseUp); 
    down.addEventListener(MouseEvent.MOUSE_DOWN, onDownClick); 
    down.addEventListener(MouseEvent.MOUSE_UP, MouseUp); 
    right.addEventListener(MouseEvent.MOUSE_DOWN, onRightClick); 
    right.addEventListener(MouseEvent.MOUSE_UP, MouseUp); 

在不關閉onKeyUp函數中還存在另一個括號問題。

這導致它認爲您的所有事件處理函數都在該函數中。

但正如我在我的評論中所說,這實際上不是調試你的應用程序論壇。

請花時間根據我的要求驗證括號。當你沒有花時間檢查被發現是一個問題的東西時,它並沒有顯示出對某人時間的很多讚賞。請花點時間驗證每個功能的所有括號,並且您將節省很多時間。

+0

我修復了這個問題,還是不行,還有其他的想法? – WackyTeeth 2013-04-06 17:45:43

+0

你是否得到相同的錯誤?這是你的文檔類嗎? – prototypical 2013-04-06 17:48:02

+0

您是否確認您擁有相同數量的開/關括號?正如我所說的,你需要驗證這個方面。 – prototypical 2013-04-06 17:49:35