Hello! Help me please to the mission to decide. Hello! Help me please to the mission to decide.

Hello! Help me please to the mission to decide. It is difficult for me yet:)

Mission: Object includes 9 items (box1, box2...). Can I do so that when certain elements of the object approach to the scene, it is stopped (magnetic, takers) around the Center? And what is the function that I can use?

I use this code:

var ms: MouseSpeed = new MouseSpeed();

var xSpeed:Number = 0;

var ySpeed:Number = 0;

var friction: Number = 0.85;

var offsetX:Number = 0;

var offsetY: Number = 0;

object.buttonMode = true;

object.addEventListener (MouseEvent.MOUSE_DOWN, mouseDownHandler);

object.addEventListener (Event.ENTER_FRAME, throwobject);

park_mc. Height = stage.stageHeight * 3;

park_mc. Width = stage.stageWidth * 3;

function mouseDownHandler(e:MouseEvent):void

{

stage.addEventListener (Event.ENTER_FRAME, drag);

stage.addEventListener (MouseEvent.MOUSE_UP, mouseUpHandler);

offsetX = mouseX - object.x.

offsetY = mouseY - object.y;

}

function mouseUpHandler(e:MouseEvent):void

{

stage.removeEventListener (Event.ENTER_FRAME, drag);

stage.removeEventListener (MouseEvent.MOUSE_UP, mouseUpHandler);

xSpeed = ms.getXSpeed ();

ySpeed = ms.getYSpeed ();

}

function drag(e:Event):void

{

Object.x = mouseX - offsetX;

Object.y = mouseY - offsetY;

}

function throwobject(e:Event)

{

Object.x += xSpeed;

Object.y += ySpeed;

Object1.x = (object1.x - mouseX) / 16;

Object1.y = (object1.y - mouseY) / 16;

xSpeed * = friction;

ySpeed * = friction;

If (object.x > park_mc.width - object.width/9)

{

Object.x = park_mc.width - object.width/9;

xSpeed * = - 1;

}

if(Object.x < Object.Width/9)

{

Object.x = object.width/9;

xSpeed * = - 1;

}

If (object.y > park_mc.height - object.height/9)

{

Object.y = park_mc.height - object.height/9;

ySpeed * = - 1;

}

if(Object.y < Object.Height/9)

{

Object.y = object.height/9;

ySpeed * = - 1;

}

}

Thank you!

1 you should end your loop of throwobject when you drag the object and restart when the object is deleted.

2. have throwobject and drag call a new function where you browse through the children of the object seeking the proximity of the center of the stage.  If a child is 'close' it reparenting so it is no longer affected by the movement of the object.

Tags: Adobe Animate

Similar Questions

Maybe you are looking for