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

my object go away from the stage

Explorer ,
Jan 06, 2019 Jan 06, 2019

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;

  }

587
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

Community Expert , Jan 07, 2019 Jan 07, 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

Translate
Community Expert ,
Jan 06, 2019 Jan 06, 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

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
Explorer ,
Jan 06, 2019 Jan 06, 2019

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

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
Community Expert ,
Jan 07, 2019 Jan 07, 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

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
Explorer ,
Jan 07, 2019 Jan 07, 2019

thank you so much its work

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
Community Expert ,
Jan 08, 2019 Jan 08, 2019
LATEST

You're welcome!

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