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

my object go away from the stage

Explorer ,
Jan 06, 2019 Jan 06, 2019

Copy link to clipboard

Copied

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;

  }

Views

400

Translate

Translate

Report

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

Votes

Translate

Translate
Community Expert ,
Jan 06, 2019 Jan 06, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

thank you so much its work

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

You're welcome!

Votes

Translate

Translate

Report

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