开发者

Check if movieclip is inside another movieclip [AS3]

I need help creating a function that will check if a movieclip is inside another movieclip in actionscript 3.0. I create开发者_StackOverflow社区d a movieclip called MyImage, which is dragged around by the user on top of another movieclip called BannerStage. When the user stops dragging MyImage, the function should return true or false, true if MyImage is inside of BannerStage and false if all corners of MyImage are outside of BannerStage.

Thanks in advance.

EDIT:

My Solution:

var inter = firstClip.getRect(this).intersection(secondClip.getRect(this));
if ((inter.width*inter.height) == 0) {
    return false;
} else {
    return true;
}


Try this if you want to test if all corners of one are in all corners of the other:

banner.getRect().containsRect(draggable.getRect());

// or the reverse

draggable.getRect().containsRect(banner.getRect());

This works if they're in the same coordinate space.

If all you care about is any part of one overlapping any part of another (but you don't care if one contains the other completely) then a simple hitTestObject works.

draggable.hitTestObject(banner);
// or
banner.hitTestObject(draggable);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜