2013-04-15 3 views
0

현재 드래그 앤 드롭 가능한 여러 텍스트 필드를 만들려고합니다. 난 당신이 사용하는 것이 예로 쿼드를 사용 이전 튜토리얼은 다음되었다 : 쿼드을 대상으로 Starling textField 터치 이벤트

var target:Quad = event.target as Quad; 

당신이 위로 가져 가면 있다고, 나는 컴파일에

var target:TextField = event.target as TextField; 

로 변경하려 "null 객체 참조의 속성이나 메서드에 액세스 할 수 없습니다."라는 오류 메시지가 나타납니다. 나는 누군가가 나를 위해 이것을 정리할 수 있다면 그것은 큰 문제가 될 것이 확실하지 않다.

public function onAdded():void{ 
//stuff that initialises bitmap 

for(var i:int=0; i<3; i++){ 

      //create Textfield 
      var bmpFont:starling.text.TextField = new starling.text.TextField(100,100, "test", "Arial", 10); 

      bmpFont.fontSize = 50; 
      if(i==0){ 
       bmpFont.color = Color.WHITE; 

      } 
      else if (i==1){ 
       bmpFont.color = Color.RED; 
      } 

      else if (i==2){ 
       bmpFont.color = Color.BLUE; 
      } 

      bmpFont.x = Math.random() * (stage.stageWidth - bmpFont.width); 
      bmpFont.y = stage.stageHeight/2; 
      //centering pivot point 
      bmpFont.pivotX = 50; 
      bmpFont.pivotY = 50; 

      //centering code 
      //bmpFont.x = stage.stageWidth - bmpFont.width >> 1; 
      //bmpFont.y = stage.stageHeight - bmpFont.height >> 1; 

      useHandCursor = true;     
      bmpFont.addEventListener(starling.events.TouchEvent.TOUCH, onTouch); 
      parent.addChild(bmpFont); 

      } 

ontouch 기능 :

 //function activating on touch 
     public function onTouch(event:starling.events.TouchEvent):void{ 
      var touches:Vector.<Touch> = event.getTouches(stage, TouchPhase.MOVED); 
      //var target:Quad = event.target as Quad; 

      var target:starling.text.TextField= event.target as starling.text.TextField 

      //single finger manipulations 
      if(touches.length == 1){ 
       var delta:Point = touches[0].getMovement(parent); 
       target.x += delta.x; 
       target.y += delta.y; 
      } 
+0

당신이 캐스팅가 널이 발생하지 않는다는 것을 확신하려고 여기

코드의 나머지 부분은 관련 그게 전부입니다 목표물? var target : starling.text.TextField = event.target as starling.text.TextField –

+0

당신이 무엇을 의미하는지 잘 모르겠습니다. – David

+0

시작 후 즉시 textField를 이동하려고 시도 할 때 오류가 발생한다는 것을 잊어 버렸습니다. – David

답변

0

//function activating on touch 
    public function onTouch(event:starling.events.TouchEvent):void{ 
     var target:starling.text.TextField= event.target as starling.text.TextField; 
     var touches:Vector.<Touch> = event.getTouches(target, TouchPhase.MOVED); 


     //single finger manipulations 
     if(touches.length == 1){ 
      var delta:Point = touches[0].getMovement(target.parent); 
      // delta and target should be not null 

      target.x += delta.x; 
      target.y += delta.y; 
     } 
+0

더 이상 오류가 발생하지 않지만 TextFields는 이동하지 않습니다 – David

+0

추적을 수행했는데 어떤 손가락이든 감지하지 못하는 것 같습니다. 쿼드 예제는 "var target : Quad = event.target Quad;"였습니다. 그것은 미세한 요소를 만지는 것을 감지 한 것 같습니다. – David

+0

델타가 계산 될 때 문제가 있음을 의미합니다. 중단 점을 사용하고 delta.x 및 delta.y 값이 무엇인지 확인하십시오. 또한 touch [0] .getMovement (this) 또는 getMovement (stage)를 계산하려고 시도합니다. 죄송 합니다만 코드를 디버깅 할 수 없습니다. 제가 볼 수있는 것은 당신이 starling help page의 원본 샘플을 약간 엉망으로 만든다는 것입니다. –