Skip to main content
Kumineko
Participating Frequently
August 13, 2017
Answered

Zoom In/Out and Pan in As3

  • August 13, 2017
  • 1 reply
  • 3468 views

Hi all I am using Animate CC.

So i don't know if that action script 3 or not. My apologies if its not. I am new to Animate CC and Flash/Actionscript.

Anyhow i am doing an interactive map and map turned out rather big for the html i tend to put it on. Thus after spending a day or two trying to find the answer having no luck, I decided to ask here.

All I want is that i can pan the image, and zoom in/out the image using the mouse.

Please help,

Jorge

    This topic has been closed for replies.
    Correct answer Colin Holgate

    It could be that when the object becomes big enough to be under the mouse, or if you happen to start that way, but I can't get it to go wrong.

    You should add the listener to a background movieclip, so that you can zoom AzS smaller, the background movieclip would still get the mouse events when the cursor isn't over AzS. You would also want to stop AzS from triggering mouse events. I made a background movieclip, bg, and here's my version:

    import flash.events.MouseEvent;

    bg.addEventListener(MouseEvent.MOUSE_WHEEL, zoom);

    AzS.mouseEnabled = false;

    AzS.mouseChildren = false;

    function zoom(e: MouseEvent): void {

        if (e.delta > 0) {

            AzS.width += 20;

            AzS.height += 20;

        } else if (e.delta < 0) {

            AzS.width -= 20;

            AzS.height -= 20;

        }

    }

    BTW, it only works in the debug player or in a browser. It won't work as a normal Test Movie.

    1 reply

    Kumineko
    KuminekoAuthor
    Participating Frequently
    August 13, 2017

    While checking the web i came across this code. Which i modified as AzS is the name of the image converted to a movie. But whenever i run it, it comes up with the following error: Scene 1, Layer 'action', Frame 1, Line 20, Column 7 1119: Access of possibly undefined property width through a reference with static type Class.

    So I am assuming is have define the movie variable some how but i dont know how.

    import flash.events.MouseEvent;

    addEventListener(MouseEvent.MOUSE_WHEEL, zoom);

    function zoom(e: MouseEvent): void {

    if (e.delta > 0) {

    AzS.width += 20;

    AzS.height += 20;

    } else if (e.delta < 0) {

    AzS.width -= 20;

    AzS.height -= 20;

    }

    }

    Colin Holgate
    Colin HolgateCorrect answer
    Inspiring
    August 13, 2017

    It could be that when the object becomes big enough to be under the mouse, or if you happen to start that way, but I can't get it to go wrong.

    You should add the listener to a background movieclip, so that you can zoom AzS smaller, the background movieclip would still get the mouse events when the cursor isn't over AzS. You would also want to stop AzS from triggering mouse events. I made a background movieclip, bg, and here's my version:

    import flash.events.MouseEvent;

    bg.addEventListener(MouseEvent.MOUSE_WHEEL, zoom);

    AzS.mouseEnabled = false;

    AzS.mouseChildren = false;

    function zoom(e: MouseEvent): void {

        if (e.delta > 0) {

            AzS.width += 20;

            AzS.height += 20;

        } else if (e.delta < 0) {

            AzS.width -= 20;

            AzS.height -= 20;

        }

    }

    BTW, it only works in the debug player or in a browser. It won't work as a normal Test Movie.

    Kumineko
    KuminekoAuthor
    Participating Frequently
    August 13, 2017

    for some reason that code comes up with an error when the:

    AzS.width += 20;

    Scene 1, Layer 'action', Frame 1, Line 8, Column 13 1119: Access of possibly undefined property width through a reference with static type Class.

    When it goes thru bg.addEventListener(MouseEvent.MOUSE_WHEEL, zoom);

    Scene 1, Layer 'action', Frame 1, Line 2, Column 1 1120: Access of undefined property bg.

    I dont know what this errors mean.