2014-10-12 112 views
0

顯然,我的代碼不讓我爲我的交互式事物創建一個39(左箭頭鍵),因爲我的任務需要幫助。作爲一名大學生,這是我作爲一種新語言,Adobe Actionscript 3.0是這裏使用的語言。1120:未定義屬性的訪問k

package { 

import flash.display.MovieClip; 
import flash.events.MouseEvent; 
import flash.events.KeyboardEvent; 


public class Main extends MovieClip 
{ 
    //Global variables, as in it's beyond the local as in the entire coding not one part 
    var idiot 


    public function Main() { 
     // constructor code 

     idiot = new RedCircle 
     addChild(idiot); 
     idiot.x = Math.random()* (stage.stage.width) 
     idiot.y = Math.random()* (stage.stage.height) 

     if (idiot.x > stage.stageWidth/2 && idiot.y < stage.stageHeight/2) 
     { 
      trace ("aaaahhhhh") 
      idiot.rotation = 135 
     } 

     //Interactive side 
     idiot.addEventListener(MouseEvent.CLICK, shootsnot); 
     stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed); 

    }// Main() 

    public function shootsnot (n:MouseEvent) 

    { 
     //shoot snot 
     trace ("NEVER ENDING DAKKA"); 

     var snotty = new Snot(); 
     addChild(snotty) 
     snotty.x = idiot.x 
     snotty.y = idiot.y + idiot.height/2; 

    } 

    public function keyPressed (n:KeyboardEvent) 

    { 
     //pressing something 
     trace ("Key Pressed") 

     trace(k.keyCode); 

     if (k.keyCode == 37) 

     { 
      //left press 
      idiot.x = idiot.x - 10 
     } 



    } 

    } 


    } 

回答

2

問題很簡單,k不會在你的代碼的任何地方存在,但是n一樣。

一個爲您解決問題的辦法是更換

public function keyPressed(n:KeyboardEvent) 

public function keyPressed(k:KeyboardEvent)