Copy link to clipboard
Copied
Im new to coding and been practicing for a shol project.
Im trying to put a fuction on an element so it doubles the size on a double click, and then zoom out again if double clicked again.
Ive been trying this with gesture events, yet im not having much luck, ive been trying with press and hold as well.
Any help on how i could do this?
Here is an example. If you have a movieclip on the stage named "ball", this will do what you claim to want:
import flash.events.Event;
import fl.transitions.Tween;
import fl.transitions.easing.*;
ball.doubleClickEnabled = true;
ball.addEventListener(MouseEvent.DOUBLE_CLICK, doZoom);
function doZoom(e:Event):void {
var _this = e.target;
if (!_this.init) {
_this.init = true;
_this.zoomed = false;
_this.origXS = _this.scaleX;
_this.origYS = _this.scaleY;
}
var zoom
...Copy link to clipboard
Copied
You're asking two questions-- how do you detect a double tap, or how do you zoom. Which is it?
Copy link to clipboard
Copied
Oh, both questions then, i think
Copy link to clipboard
Copied
And is this an AS3 or Canvas project?
Copy link to clipboard
Copied
It is AS3
Copy link to clipboard
Copied
Here is an example. If you have a movieclip on the stage named "ball", this will do what you claim to want:
import flash.events.Event;
import fl.transitions.Tween;
import fl.transitions.easing.*;
ball.doubleClickEnabled = true;
ball.addEventListener(MouseEvent.DOUBLE_CLICK, doZoom);
function doZoom(e:Event):void {
var _this = e.target;
if (!_this.init) {
_this.init = true;
_this.zoomed = false;
_this.origXS = _this.scaleX;
_this.origYS = _this.scaleY;
}
var zoomScale:Number = 2;
var zoomFrames:Number = 15;
if (!_this.zoomed) {
// zoom
_this.zoomed = true;
new Tween(_this, "scaleX", Strong.easeOut, _this.scaleX, zoomScale, zoomFrames);
new Tween(_this, "scaleY", Strong.easeOut, _this.scaleY, zoomScale, zoomFrames);
}
else {
// unzoom
_this.zoomed = false;
new Tween(_this, "scaleX", Strong.easeOut, zoomScale, _this.origXS, zoomFrames);
new Tween(_this, "scaleY", Strong.easeOut, zoomScale, _this.origYS, zoomFrames);
}
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now