2013-10-22 3 views
0

이 코드를 사용하면 "1061 : 정적 유형 클래스가있는 참조를 통해 hitTestPoint 가능성이있는 정의되지 않은 메서드 호출"오류가 발생합니다.정의되지 않은 hitTestPoint 오류

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

public class Code extends MovieClip { 

    var charSpeed:int = 0; 
    var velocity:int = 0; 
    var gravity:Number = 1; 
    var Jump:Boolean = false; 


    public function startGame(){ 
     stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeyDown); 
     stage.addEventListener(KeyboardEvent.KEY_UP, checkKeyUp); 
     stage.addEventListener(Event.ENTER_FRAME, loop); 
    } 

    public function Code() { 
     // constructor code 
    } 

    function checkKeyDown(evt:KeyboardEvent){ 
     if (evt.keyCode == Keyboard.LEFT){ 
      charSpeed -= 10; 
     } 
     if (evt.keyCode == Keyboard.RIGHT){ 
      charSpeed += 10; 
     } 
     if (evt.keyCode == Keyboard.DOWN){ 
      if(!Jump){ 
       velocity -= 14; 
       Jump = true; 
      } 
     } 
    } 

    function checkKeyUp(evt:KeyboardEvent){ 
     if (evt.keyCode == Keyboard.LEFT){ 
      charSpeed = 0; 
     } 
     if (evt.keyCode == Keyboard.RIGHT){ 
      charSpeed = 0; 
     } 
    } 

    function loop(evt:Event){ 
     player.x = velocity; 
     if (player.x < 0){ 
      player.x = 0; 
     } 
     if (player.x > 550){ 
      player.x = 550; 
     } 

     velocity += gravity; 

     if (!platform.hitTestPoint(player.x, player.y, true)){ 
      player.y += velocity; 
     } 

     for (var i = 0; i < 10; i++){ 
      if (platform.hitTestPoint(player.x, player.y, true)){ 
       player.y--; 
       velocity = 0; 
       Jump = false; 
      } 
     } 
    } 
} 
} 

내 플랫폼에 무비 클립 변수를 추가하고 있었다, 그리고이 오류를 제거했지만 내 변수에 플랫폼의 내 실제 인스턴스를 연결하는 방법을 잘하지 않았다 옵션. 아, 그런데 플랫폼의 인스턴스는 플랫폼입니다. 누구든지이 오류를 수정하는 방법에 대한 단서가 있다면, 그것은 좋을 것입니다. 당신이 코드 인스턴스를 만들 때

+0

나는 당신의 플랫폼의 클래스 이름 platform' 제대로 클래스 이름을 활용하려고'도 기대 - 인스턴스이며, AS3 연계는'Platform'이다. – Vesper

답변

0

당신은 생성자

public function class Code { 

    //assume Platform is the class type,remember to import it 
    private var platform:Platform; 

    public function Code(value:Platform) { 
     platform = value; 
    } 

} 

의 플랫폼 값을 설정할 수 있습니다

var code:Code = new Code(platform);//platform is the instance