Flash CS6 / AS3: Drag and Resize a rectangle movieclip

636 views Asked by At

Not sure if this is possible but going to ask: is there a way of being able to resize a symbol (in this case, a movie clip) in an swf file by clicking and dragging it with your cursor?

One of the things I need to do is have a rectangle within my published swf file that can be resized in height and width by clicking and dragging the sides or corner of the rectangle. Not sure at all how to do this, though. Any tutorials I could look at or maybe something that's somewhat easy to do/explain here? Right now from what little I've found on the subject, it seems like a complex thing to do.

Thanks.

2

There are 2 answers

0
Lodewijck On BEST ANSWER

There is no standard option for that, so you have to code it yourself. My suggestion:

You could add a small MovieClip, looking like an arrow, right next to your scalable item. Make this arrow horizontally draggable and whenever you drag this arrow, update the width of the scalable item according to the new position of the arrow. In this case you can scale your item horizontally, but you can use the same approach to make it vertically or diagonally scalable.

0
dzinermachine On

@Lodewijck - Your suggestion worked, thank you!!

This may not be the best way to write the code but it worked:

stop();

import flash.events.MouseEvent;

stage.addEventListener(MouseEvent.MOUSE_MOVE,resize1);
this.addEventListener(MouseEvent.MOUSE_DOWN, startDragging, true);
this.addEventListener(MouseEvent.MOUSE_UP, stopDragging, true);

function startDragging(e:MouseEvent) {

dragsquare.startDrag();

}

function stopDragging(e:MouseEvent) {

dragsquare.stopDrag();

}

function resize1(E:MouseEvent){
square1.width=dragsquare.x - square1.x;
square1.height=dragsquare.y - square1.y;
}