How can I constrain an image in a container to only a horizontal drag that when it collides with another image 'pushes' that开发者_运维问答 image along that same horizontal line.
-------o------o--
public function hitTestIMG1(yourEvent:Event):void
{
if(IMG1.hitTestObject(IMG2)) {
if(IMG1.x < IMG2.x-(IMG2.width/2)) {
trace("LEFT SIDE!!!");
trace("IMG1: " + IMG1.x);
trace("IMG1 Width: " + IMG1.width);
trace("IMG2: " + IMG2.x);
trace("IMG2 Width: " + IMG2.width);
IMG2.x = IMG1.x+(IMG1.width);
} else
if(IMG1.x > IMG2.x+(IMG2.width/2)) {
trace("RIGHT SIDE!!!");
trace("IMG1: " + IMG1.x);
trace("IMG1 Width: " + IMG1.width);
trace("IMG2: " + IMG2.x);
trace("IMG2 Width: " + IMG2.width);
IMG2.x = IMG1.x-(IMG2.width);
}
}
}
public function IMG1Start(IMGMove:Event):void
{
IMG1.startDrag(false,new Rectangle(0,IMG1.y,stage.width,0));
}
public function IMG1Stop(IMGStop:Event):void
{
IMG1.stopDrag();
}
public function test():void
{
// stage listeners - must be set on startup!!!
stage.addEventListener(Event.ENTER_FRAME, hitTestIMG1);
}
]]>
file:///C|/Users/austink/Documents/Flex Builder 3/NewMenuSystem/src/assets/thumbs/IMG8.png file:///C|/Users/austink/Documents/Flex Builder 3/NewMenuSystem/src/assets/thumbs/IMG12.png
精彩评论