Drag and scale proportionally

Code Actionscript 2.0

Instance action

on (press) {
mousepressed = 1;
}
on (release, releaseOutside) {
mousepressed = 0;
}
onClipEvent (enterFrame) {
if (mousepressed == 1) {
dx = _root._xmouse - this._x;
proportion = this._height / this._width;
this._width = dx;
this._height = dx * proportion;
}
}

Code Actionscript 3.0

addEventListener(Event.ENTER_FRAME, enterFrame); pic.addEventListener(MouseEvent.MOUSE_DOWN, press); pic.addEventListener(MouseEvent.MOUSE_UP, release); stage.addEventListener(MouseEvent.MOUSE_UP, releaseOutside); var mousepressed=0; function press(e:MouseEvent) { mousepressed = 1; } function release(e:MouseEvent){ mousepressed = 0; } function releaseOutside(e:MouseEvent){ mousepressed = 0; } function enterFrame(event:Event) { if (mousepressed == 1) { var dx = mouseX - pic.x; var proportion = pic.height / pic.width; pic.width = dx; pic.height = dx * proportion; } } // image cc by http://www.flickr.com/photos/indigoprime/

Description

When the mouse clicks on the picture, the proportions are kept and the image scales to match the position of the mouse. Because the dimensions of the picture are determined by the enterFrame-handler, it can be continuously modified as the mouse is pressed and dragged throughout the frame.

related to: Drag and scale

Download

Right click: Flashfile AS 2.0 | Flashfile AS 3.0 | SWF-File


Share