2016-10-20 9 views
0

私はドラッグアンドドロップゲームで使用したい画像をいくつか持っています。私はこれをactionscriptコードスニペットで処理していますが、ボトムコーナーに矢印などをドラッグしてサイズを変更できるようにするには、これらの画像も必要です。私は、サイズ変更コードを含まないことでドラッグを動作させることも、その逆も可能です。ドラッグで画像のサイズを変更するにはどうすればよいですか?

this.addEventListener(MouseEvent.MOUSE_MOVE, resize); 
this.addEventListener(MouseEvent.MOUSE_UP, stopDragging, true); 
this.addEventListener(MouseEvent.MOUSE_DOWN, startDragging, true); 
function startDragging(E:MouseEvent):void { 
    resize1.startDrag(); 
} 

function stopDragging(E:MouseEvent):void { 
    resize1.stopDrag(); 
} 
function resize(E:MouseEvent):void { 
    item1_mc.width = resize1.x - item1_mc.x; 
    item1_mc.height = resize1.y - item1_mc.y; 
} 

これを修正する方法はありますか?画像のサイズ変更コードは現時点では基本的なものですが、すぐにスケーリングに変更することができます。

+0

キャプチャがtrueに設定されている理由はありますか? –

答えて

1

あなたは、あなたのイメージムービークリップを分割する必要がある(またはあなたが持っているものは何でも)2つの部分に - あなたの「myImageWidget」INその後、その

myImageWidget (this is your parent movicelip) 
| 
|- imageMC (this will hold the image and will be the draggable object) 
|- arrowMC (this is your arrow that will be OVER your image and will be used to resize) 

などのサイズ変更、ドラッグ可能な1と1あなたはこのような何か(を取り除くを必要としますすべて「これ」の意味ではありません。

// image MC will listen for clicks and start dragging 
imageMC.addEventListener(MouseEvent.MOUSE_UP, stopDragging, true); 
imageMC.addEventListener(MouseEvent.MOUSE_DOWN, startDragging, true); 

// arrow MC will listen for clicks and start resizing 
arrowMC.addEventListener(MouseEvent.MOUSE_UP, stopResizing, true); 
arrowMC.addEventListener(MouseEvent.MOUSE_DOWN, startResizing, true); 

function startDragging(E:MouseEvent):void 
{ 
    startDrag(); 
} 

function stopDragging(E:MouseEvent):void 
{ 
    stopDrag(); 
} 

function startResizing(E:MouseEvent):void 
{ 
    addEventListener(MouseEvent.MOUSE_MOVE, resize); 
} 

function stopResizing(E:MouseEvent):void 
{ 
    removeEventListener(MouseEvent.MOUSE_MOVE, resize); 
} 

function resize(E:MouseEvent):void 
{ 
    // you will adjust this to local coordinates since you are inside of the imageWidget 
    width = mouseX; 
    height = mouseY; 
} 
+0

お手数ですが助けてください!それは理にかなっているように見え、必要な場所にドラッグできるようになっています。唯一の問題は、サイズ変更したいムービークリップの隣に配置された別のムービークリップである矢印のドラッグが何もしていないことです。動きはなく、サイズ変更もありません。理由は何ですか? – user2047366

+0

あなたは矢印のムービークリップをウィジェットの中に入れます。あなたは別だと言っています...? –

+0

後で追加されたイベントが呼び出されないようにするには、 'stopPropagation()'コールを行う必要があります。私はコメントでそれをすべて説明することはできませんが、あなたはそれをGoogleにすることができます。基本的に矢印と画像が重なっているかどうかによって異なります –

関連する問題