Skip to main content
tomj63754343
Participant
April 14, 2020
Question

How can we use as3 to stretch images?

  • April 14, 2020
  • 1 reply
  • 293 views

Looking for a way to code, "When Dragged On Image, Push, Pull, Stretch pixels.
I want to be able to distort images I publish by Click & Dragging and via Mouse Wheel. Would be ideal if: Drag to stretch, and mouse wheel to scale images.

Signed: Clueless

    This topic has been closed for replies.

    1 reply

    avtutorials
    Known Participant
    April 14, 2020

    Hi Tom,

    I'm not sure if this would do it for you, and I don't know how to use the mouse wheel as a programmatic input device -- never done that before.

    But, I'd make the image as a MovieClip (MC): call it mainImage.  I'd make another graphic object as MC that acts a "dragging handle,": call it draggingHandle.

    I'd put draggingHandle on top of the edge of mainImage.

    This code should work:

    var mainImageOrigWidth = mainImage.width;
    
    draggingHandle.addEventListener(MouseEvent.MOUSE_DOWN,startDragging);
    draggingHandle.addEventListener(MouseEvent.MOUSE_UP,stopDragging);
    
    function startDragging(e:MouseEvent):void{
    	draggingHandle.startDrag();
    }
    
    function stopDragging(e:MouseEvent):void{
    	mainImage.scaleX = (draggingHandle.x - mainImage.x) / mainImage.width;
    	draggingHandle.stopDrag();
    }