現在、ドラッグ アンド ドロップ可能な複数のテキスト フィールドを作成しようとしています。使用する例としてクワッドを使用した以前のチュートリアルに従っていました。
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);
}
オンタッチ機能:
//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;
}