Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

double tap to ZOOM

New Here ,
May 03, 2017 May 03, 2017

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?

580
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 03, 2017 May 03, 2017

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

...
Translate
LEGEND ,
May 03, 2017 May 03, 2017

You're asking two questions-- how do you detect a double tap, or how do you zoom. Which is it?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 03, 2017 May 03, 2017

Oh, both questions then, i think

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 03, 2017 May 03, 2017

And is this an AS3 or Canvas project?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 03, 2017 May 03, 2017

It is AS3

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 03, 2017 May 03, 2017
LATEST

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);

    }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines