Skip to main content
February 3, 2010
Question

AS3 İmage Panning Code(urgent!!!!)

  • February 3, 2010
  • 1 reply
  • 3381 views

Hi,

İ have been googling it since 3 hours and could not find it(those that i found are not working)....

İ need a code that i can pan anything in stage - does not matter a bitmap or movieclip- i need interactive stage pan....

if it is not possible on the main stage, just give me the code for a specific image

ty so much

Good night.....

This topic has been closed for replies.

1 reply

February 3, 2010

What is the problem? Do you need to pan individual objects, by click dragging them, or pan all objects on the stage at one time?

Essentially, all you need to do is listen for a click on the object to be panned... when you get it, start an enter frame handler that moves the object to the mouse position.

February 3, 2010

Ty for the fast relpy!

can you write a small version code of what you talking about;

really tyx i am newbie at this

February 3, 2010

OK - if you want to pan some display object - be it a single object, or a container with other things doesn't matter. It would go something like so:

var deltaX:int;

var deltaY:int;

myContainer.addEventListener(MouseEvent.MOUSE_DOWN, beginPan, false, 0, true); //pan myContainer

function beginPan(e:MouseEvent):void
{   
    deltaX = mouseX - myContainer.x;           
    deltaY = mouseY - myContainer.y;
           
    addEventListener(Event.ENTER_FRAME, doPan, false, 0, true);
    stage.addEventListener(MouseEvent.MOUSE_UP, endPan, false, 0, true);

}

function doPan(e:Event):void
{
    var curX:int = mouseX - deltaX;
    var curY:int = mouseY - deltaY;

    myContainer.x = curX;

    myContainer.y = curY;

}


function endPan(e:MouseEvent):void

{

    stage.removeEventListener(MouseEvent.MOUSE_UP, endPan);
    removeEventListener(Event.ENTER_FRAME, doPan);

}

That should be all you need - aside from probably adding some limits in the doPan function, so you can't drag the item out of view.

Let me know if this works for you.