繁体   English   中英

如何单击一个圆以显示围绕它的矩形? 使用Flash as3.0

[英]how to click a circle to show a rectangle surrounding it ?? using flash as3.0

我是新手。 我想单击一个圆以显示一个围绕它的矩形,然后在此阶段单击任何其他地方以隐藏此矩形,如何实现此事件?

谢谢您的帮助!!!

在Sprite中画圆。 以编程方式,这可以通过以下方式完成:

var circle : Sprite = new Sprite();
circle.graphics.beginFill(0xffcc00);
circle.graphics.drawCircle(20, 20, 20); // center x, y and radius
addChild(circle);

当有人单击它时,请使用getBounds()方法获取一个Rectangle实例,该实例定义圆的边界矩形(以避免对其尺寸进行硬编码。)使用此Rectangle实例中的信息绘制一个矩形。

// Create an empty Sprite into which we will draw our rectangle
var rect : Sprite = new Sprite();

circle.addEventListener(MouseEvent.CLICK, handleCircleClick);
function handleCircleClick(ev : MouseEvent) : void {
    var bounds : Rectangle;

    // Draw rectangular graphics into the rect sprite
    bounds = circle.getBounds(circle.parent);
    rect.graphics.beginFill(0x00ff00);
    rect.graphics.drawRect(bounds.left, bounds.top, bounds.width, bounds.height);

    // Add rect to stage, below circle
    circle.parent.addChildAt(rect, 0);
}

我会把它留给您作为练习,以在用户在圆圈外单击时隐藏rect sprite。

请注意,这只是这样做的一种方法,但是由于您对设置没有任何解释,也没有提供有关案例的详细信息,因此这是我想到的最简单的方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM