0

如何将容器中的图像限制为仅水平拖动,当它与另一个图像碰撞时,该图像沿同一水平线“推动”该图像。

--------o--------o--

4

1 回答 1

0

    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

于 2011-03-03T21:53:21.803 回答