Highlighted

my object go away from the stage

Community Beginner ,
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;

  }

Adobe Community Professional
Correct answer by JoãoCésar | Adobe Community Professional

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

Views

237

Likes

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

my object go away from the stage

Community Beginner ,
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;

  }

Adobe Community Professional
Correct answer by JoãoCésar | Adobe Community Professional

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

Views

238

Likes

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
Jan 06, 2019 0
Adobe Community Professional ,
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

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

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
Reply
Loading...
Jan 06, 2019 0
Community Beginner ,
Jan 06, 2019

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Jan 06, 2019 0
Adobe Community Professional ,
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

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

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
Reply
Loading...
Jan 07, 2019 0
Community Beginner ,
Jan 07, 2019

Copy link to clipboard

Copied

thank you so much its work

Likes

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
Reply
Loading...
Jan 07, 2019 1
Adobe Community Professional ,
Jan 08, 2019

Copy link to clipboard

Copied

You're welcome!

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

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
Reply
Loading...
Jan 08, 2019 0