Skip to main content
Known Participant
January 6, 2019
Answered

my object go away from the stage

  • January 6, 2019
  • 3 replies
  • 680 views

when i move my object x .. it go away from the stage .. can u help me with function make my  object moving inside the stage?! thanx a lot

stop();

stage.addEventListener(MouseEvent.MOUSE_MOVE,mousedown);

function mousedown(e:MouseEvent):void{

  girlMc.x = mouseX;

  }

    This topic has been closed for replies.
    Correct answer JoãoCésar17023019

    Hi.

    You can use:

    import flash.events.Event;

    function mouseMoveHandler(e:Event):void

    {

        girlMc.x = mouseX;

        if (girlMc.x < 0)

              girlMc.x = 0;

        else if (girlMc.x > stage.stageWidth - girlMc.width)

              girlMc.x = stage.stageWidth - girlMc.width;

    }

    stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);

    I hope this helps.

    Regards,

    JC

    3 replies

    Known Participant
    January 8, 2019

    thank you so much its work

    JoãoCésar17023019
    Community Expert
    Community Expert
    January 8, 2019

    You're welcome!

    Known Participant
    January 6, 2019

    i need move object while the cursor is moving .registration point of  girlMc in top left

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    January 7, 2019

    Hi.

    You can use:

    import flash.events.Event;

    function mouseMoveHandler(e:Event):void

    {

        girlMc.x = mouseX;

        if (girlMc.x < 0)

              girlMc.x = 0;

        else if (girlMc.x > stage.stageWidth - girlMc.width)

              girlMc.x = stage.stageWidth - girlMc.width;

    }

    stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);

    I hope this helps.

    Regards,

    JC

    JoãoCésar17023019
    Community Expert
    Community Expert
    January 6, 2019

    Hi.

    Do you need to move your object while the cursor is moving or only when you press the mouse left button?

    Also, where the registration point of your girlMc instance is located? Top left, center...?

    Regards,

    JC