package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.media.Sound;
import flash.ui.Mouse;
public class bakingCake extends MovieClip {
public function bakingCake() {
// constructor code
var object:MovieClip = new MovieClip;
a.addEventListener(MouseEvent.MOUSE_DOWN,objectA);
b.addEventListener(MouseEvent.MOUSE_DOWN,objectB);
if (object.hitArea(c) == true)
{
c.x = 300;
}
function objectA():void
{
object = a;
object.addEventListener(MouseEvent.MOUSE_OVER,objectFun);
}
function objectB():void
{
object = b;
object.addEventListener(MouseEvent.MOUSE_OVER,objectFun);
}
function objectFun(event:MouseEvent):void
{
object.addEventListener(MouseEvent.MOUSE_DOWN,drag);
object.addEventListener(MouseEvent.MOUSE_UP,sDrag);
}
function drag(event:MouseEvent):void
{
object.startDrag();
}
function sDrag(event:MouseEvent):void
{
object.stopDrag();
}
}
}
}
答案 0 :(得分:0)
你试过getBounds()吗? 我建议条件:
if (c.getBounds(c.parent).containsRect(a.getBounds(c.parent))
|| c.getBounds(c.parent).containsRect(b.getBounds(c.parent))) {
c.x = 300;
}
IMO最好的方法是检查它是否由ENTER_FRAME事件触发,为任何对象提供。