현재 드래그 앤 드롭 가능한 여러 텍스트 필드를 만들려고합니다. 난 당신이 사용하는 것이 예로 쿼드를 사용 이전 튜토리얼은 다음되었다 : 쿼드을 대상으로 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;
}
당신이 캐스팅가 널이 발생하지 않는다는 것을 확신하려고 여기
코드의 나머지 부분은 관련 그게 전부입니다 목표물? var target : starling.text.TextField = event.target as starling.text.TextField –당신이 무엇을 의미하는지 잘 모르겠습니다. – David
시작 후 즉시 textField를 이동하려고 시도 할 때 오류가 발생한다는 것을 잊어 버렸습니다. – David