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

Mouse Wheel event for zoom in and zoom out

Guest
Aug 29, 2013 Aug 29, 2013

Hi All,

I have this for my function:


var Mydelta:int;
var zoomAmt:int = 35;

addEventListener(MouseEvent.MOUSE_WHEEL, Myzoom);

function Myzoom(event:MouseEvent):void
{
Mydelta = event.delta;

if (Mydelta > 0)
{
  images_mc.width +=  zoomAmt;
  images_mc.height +=  zoomAmt;
}
else if (Mydelta < 0)
{
  images_mc.width -=  zoomAmt;
  images_mc.height -=  zoomAmt;
}
}

But I want the zoom out to stop at document size

Please help.

Thanks in advance.

TOPICS
ActionScript
4.5K
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

Guru , Aug 30, 2013 Aug 30, 2013

//scaleX is per default 1.0 use a reasonable increment

var zoomAmt:Number = .1;

function Myzoom(event:MouseEvent):void

{

    Mydelta = event.delta;

   

    if (Mydelta > 0)

    {

        images_mc.scaleX += zoomAmt;

        images_mc.scaleY += zoomAmt;

    }

    else if (Mydelta < 0)

    {

        if (images_mc.width - zoomAmt >= stage.stageWidth)

        {

            images_mc.scaleX -= zoomAmt;

        }

        if (images_mc.height - zoomAmt >= stage.stageHeight)

        {

            images_mc.scaleY -= zoom

...
Translate
Guru ,
Aug 29, 2013 Aug 29, 2013

make a condition which flash checks before it begins zooming like:

if(images_mc.width+zoomAmt<stage.stageWidth){

           images_mc.width +=  zoomAmt;

}

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
Guest
Aug 29, 2013 Aug 29, 2013

Thank you for the help.

But, after adding the condition its not zooming in at all.

I am a novice in AS  please explain.

Thank u.

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
Guest
Aug 29, 2013 Aug 29, 2013

Hi,

var Mydelta:int;
var zoomAmt:int = 30;

addEventListener(MouseEvent.MOUSE_WHEEL, Myzoom);

function Myzoom(event:MouseEvent):void
{
Mydelta = event.delta;

if (Mydelta > 0)
{
   images_mc.width +=  zoomAmt;
   images_mc.height +=  zoomAmt;
}
else if (Mydelta < 0)
{
  if (images_mc.width + zoomAmt > stage.stageWidth)
  {
   images_mc.width -=  zoomAmt;
  }
  if (images_mc.height + zoomAmt > stage.stageHeight)
  {
   images_mc.height -=  zoomAmt;
  }
}
}

Now that everything works fine.

But the zoom out stops leaving some white border around my document.

What cud be done.

Please help.

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
Guru ,
Aug 30, 2013 Aug 30, 2013

its obvious

the moment you reach the size of you stage, you immediately shrink your image

if (images_mc.width + zoomAmt > stage.stageWidth)

  {

   images_mc.width -=  zoomAmt;

  }

  if (images_mc.height + zoomAmt > stage.stageHeight)

  {

   images_mc.height -=  zoomAmt;

  }

}

so it never actually fills the whole stage.

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
Guest
Aug 30, 2013 Aug 30, 2013

Then wat could I do to just stop at my stage size.

Thank u.

And if I want the same function for a document which has multiple movieclips den wat to do???

Please help..

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
Guru ,
Aug 30, 2013 Aug 30, 2013

1.if you have multiple MovieClips that should react to your zoom function you could push all movieclips in an array

var arr:Array = new Array();

arr = [img1,img2,img3];

2.then you would declare a pointer

var pointer:int = 0;

and in your zoomEventHandler you would have to substitute

all "images_mc" with sth. like:

arr[pointer]

3.You would also need a function that handles the indexing of the pointer,

for example

function nextImage():void{

pointer++;

}

function prevImage():void{

pointer--;

}

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
Guest
Aug 30, 2013 Aug 30, 2013

Thank u for all the help.

But how cud i restrict the prev. code till only stage size.

i.e.,

var Mydelta:int;
var zoomAmt:int = 30;

addEventListener(MouseEvent.MOUSE_WHEEL, Myzoom);

function Myzoom(event:MouseEvent):void
{
Mydelta = event.delta;

if (Mydelta > 0)
{
   images_mc.width +=  zoomAmt;
   images_mc.height +=  zoomAmt;
}
else if (Mydelta < 0)
{
  if (images_mc.width + zoomAmt > stage.stageWidth)
  {
   images_mc.width -=  zoomAmt;
  }
  if (images_mc.height + zoomAmt > stage.stageHeight)
  {
   images_mc.height -=  zoomAmt;
  }
}
}

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
Guru ,
Aug 30, 2013 Aug 30, 2013

show more of you app.

(Screenshots how the images you want to zoom appear on screen.

Are they small or large (bigger than the stage))

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
Guest
Aug 30, 2013 Aug 30, 2013

no, the images are exactly of the stage size.

Normal zoom in and, zoom out has to be of only stage size.

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
Guru ,
Aug 30, 2013 Aug 30, 2013

//scaleX is per default 1.0 use a reasonable increment

var zoomAmt:Number = .1;

function Myzoom(event:MouseEvent):void

{

    Mydelta = event.delta;

   

    if (Mydelta > 0)

    {

        images_mc.scaleX += zoomAmt;

        images_mc.scaleY += zoomAmt;

    }

    else if (Mydelta < 0)

    {

        if (images_mc.width - zoomAmt >= stage.stageWidth)

        {

            images_mc.scaleX -= zoomAmt;

        }

        if (images_mc.height - zoomAmt >= stage.stageHeight)

        {

            images_mc.scaleY -= zoomAmt;

        }

    }

}

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
Guest
Aug 30, 2013 Aug 30, 2013

Thank u for all the help.

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 ,
Nov 13, 2013 Nov 13, 2013

Hi All,

Maybe some one knows how to upgrade this code for the further functionality:

I have movieclip that I'm zooming in/out, for example picture of house. It zooms the movieclip with the house, but the zooming is like around virtual center point of the whole movieclip. I want to make zoom to the place of mouse cursor coordinates, so if my mouse is over the door of the house it will zoom to the door and not like it is now zoomed to a absolute center of the movieclip.

Thanks a lot,

Will be appreciated for any help and assistance.

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
Guru ,
Nov 13, 2013 Nov 13, 2013
LATEST

I wrote sth. tat has zoomcenter correction built in:

stage.addEventListener(MouseEvent.CLICK, zoomHandler);

function zoomHandler(e:MouseEvent):void{

    var zoomFactor:Number = 1.1;

    var zoomCenter:Point = new Point(e.stageX, e.stageY);

    var mcCenter:Point = new Point(mc.x, mc.y);

    var _xCorrection:Number = mcCenter.x-zoomCenter.x;

    var _yCorrection:Number = mcCenter.y-zoomCenter.y;

    mc.scaleX +=zoomFactor-1;

    mc.scaleY +=zoomFactor-1;

    mc.x -=_xCorrection*zoomFactor*.5;

    mc.y -=_yCorrection*zoomFactor*.5;

}

you have to exchange the click event for mousewheel

and make a distinction between e.delta+/-

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