我想在拖放游戏中使用几张图片。我已经完成了动作脚本代码片段,但我还需要这些图像能够通过拖动箭头或底部类似的东西来调整大小。我可以通过不包括调整大小代码来获得拖动工作,反之亦然。
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 :(得分:1)
你必须将你的影像动画片段(或你拥有的任何东西)分成两个部分 - 一个可拖动,一个可调整大小
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)
然后在你的" myImageWidget"你需要这样的东西(摆脱所有"这个。",它没有意义:)。
// 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;
}