如何在 Flex MXML 文件中绘制圆?

发布于 2024-08-16 05:58:44 字数 591 浏览 2 评论 0原文

在我的 MXML 文件中,我有一个带有三个 vbox 的选项卡导航器。

<mx:TabNavigator width="624" height="100%">
        <mx:VBox label="Currents Quote" 
            width="100%">            
        </mx:VBox>
        <mx:VBox label="Quote Comparison" 
            width="100%">              
        </mx:VBox>
        <mx:VBox label="Reports" 
            width="100%">            
        </mx:VBox>      
</mx:TabNavigator>

在 VBox“当前报价”内,我想绘制一个圆圈。我怎样才能实现它?

In my MXML file, I have a tab navigator with three vboxes.

<mx:TabNavigator width="624" height="100%">
        <mx:VBox label="Currents Quote" 
            width="100%">            
        </mx:VBox>
        <mx:VBox label="Quote Comparison" 
            width="100%">              
        </mx:VBox>
        <mx:VBox label="Reports" 
            width="100%">            
        </mx:VBox>      
</mx:TabNavigator>

Inside the VBox "Current Quote", I want a circle to be drawn. How can I achieve it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

素罗衫 2024-08-23 05:58:44

没有定义 MXML 圆,因此您必须自己创建一个圆控件,然后可以将其包含在 MXML 中。

package mypackage
{
    class MyCircle extends UIComponent
    {
        public var x:int;
        public var y:int;
        public var radius:int;

        override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
        {
            graphics.drawCircle(x, y, radius);
        }
    }
}

然后在您的 MXML 中,如果您声明一个命名空间以在包含控件的顶部引用它,则可以使用自定义控件...

<mx:VBox label="Currents Quote" width="100%">
    <mycontrols:MyCircle x="30" y="30" radius="30"/>
</mx:VBox>

上面的代码已输入到 StackOverflow 编辑器中,因此请检查它是否有效!

Web 上有很多关于扩展 UIComponent 和 Sprite 的帮助。 Adobe 文档非常全面。

编辑:
将您的控件作为命名空间包含在封闭控件或应用程序

<mx:Application 
    xmlns:mx="http://www.adobe.com/2006/mxml" 
    xmlns:mycontrols="mypackage.*" >
<mx:Script>

HTH中

There's no MXML circle defined, so you have to create a circle control yourself and you can then include it in your MXML.

package mypackage
{
    class MyCircle extends UIComponent
    {
        public var x:int;
        public var y:int;
        public var radius:int;

        override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
        {
            graphics.drawCircle(x, y, radius);
        }
    }
}

then in your MXML you can use your custom control if you declare a namespace to refer to it at the top of your containing control...

<mx:VBox label="Currents Quote" width="100%">
    <mycontrols:MyCircle x="30" y="30" radius="30"/>
</mx:VBox>

Code above was typed into the StackOverflow editor, so check it works!

There's a lot of help on the web for extending UIComponent and Sprite. The Adobe docs are pretty comprehensive.

EDIT:
Include your controls as a namespace in the enclosing control or application

<mx:Application 
    xmlns:mx="http://www.adobe.com/2006/mxml" 
    xmlns:mycontrols="mypackage.*" >
<mx:Script>

HTH

转角预定愛 2024-08-23 05:58:44

还可以有一个选项来创建一个圆,Eclipse

Create Box 具有背景颜色(如果您想用任何颜色填充它)和特定的宽度和高度,并提供恰好一半宽度的角半径

示例:

<mx:Box cornerRadius="3"  borderStyle="solid" borderColor="0x5F4C0B" backgroundColor="0x5F4C0B" width="6" height="6" />

There can be one more option to create a circle, eclipse

Create Box with background color (if you want to fill it with any color) and with specific width and height and provide corner radius with exactly half of width

example :

<mx:Box cornerRadius="3"  borderStyle="solid" borderColor="0x5F4C0B" backgroundColor="0x5F4C0B" width="6" height="6" />
似梦非梦 2024-08-23 05:58:44

所以在 Flex 中这是一种可能性:

var mySprite:Sprite = new Sprite();
mySprite.graphics.beginFill(0xFFCC00);
mySprite.graphics.drawCircle(30, 30, 30);
this.addChild(mySprite);

这应该可行:)

So in Flex this is a possibility:

var mySprite:Sprite = new Sprite();
mySprite.graphics.beginFill(0xFFCC00);
mySprite.graphics.drawCircle(30, 30, 30);
this.addChild(mySprite);

That should work :)

栀子花开つ 2024-08-23 05:58:44

修饰拖放等...

是的,几乎一切皆有可能。如果您不想使用饼图(我建议您查看它,因为它可能会使许多绘图代码变得非常简单),那么您需要修饰上面的 MyCircle 类以捕获 mouseDown 事件并启用从它使用 DragSource 对象。

package mypackage
{
    class MyCircle extends UIComponent
    {
        ...snip...

        // to initiate a drag from this object
        private function MouseDown(e:MouseEvent):void
        {
            var ds:DragSource = new DragSource();
            if (data)
            {
                 // I'm adding the object's data to it, but you need to decide what you want in here
                ds.addData(data, "MyDragAction");
                mx.managers.DragManager.doDrag(this, ds, e);
            }
        }

        // to handle a drop
        private function HandleDrop(e:DragEvent):void
        {
            mx.managers.DragManager.acceptDragDrop(e.currentTarget);
            // you can get at whatever you put in the drag event here
        }
    }
}

您需要将这些函数(以及您最终支持拖/放的任何其他函数)设置为该对象上的事件侦听器。您可以在对象的构造函数中执行此操作,只需确保正在侦听正确的事件即可。

您需要进行一些挖掘,adobe 文档是你的朋友,但这一切都是完全可能的。当您向 MyCircle 添加更多内容时,您将通过将其分解为单独的控件而获得更大的好处。

Embellishing for drag and drop etc...

Yes, pretty much anything is possible. If you don't want to use a pie chart (which I recommend you look at because it might make a lot of the drawing code very simple) then you need to embellish the MyCircle class above to trap the mouseDown event and to enable dragging from it using a DragSource object.

package mypackage
{
    class MyCircle extends UIComponent
    {
        ...snip...

        // to initiate a drag from this object
        private function MouseDown(e:MouseEvent):void
        {
            var ds:DragSource = new DragSource();
            if (data)
            {
                 // I'm adding the object's data to it, but you need to decide what you want in here
                ds.addData(data, "MyDragAction");
                mx.managers.DragManager.doDrag(this, ds, e);
            }
        }

        // to handle a drop
        private function HandleDrop(e:DragEvent):void
        {
            mx.managers.DragManager.acceptDragDrop(e.currentTarget);
            // you can get at whatever you put in the drag event here
        }
    }
}

You'll need to set these functions (and whichever else you wind up supporting for drag/drop) as event listeners on this object. You can do that in the object's constructor, you just have to make sure you are listening for the right event.

You have some digging to do, and the adobe docs are your friend, but it is all perfectly possible. As you add more to MyCircle you will get greater benefit from having it factored out into a separate control.

箹锭⒈辈孓 2024-08-23 05:58:44

尝试以下代码:

        <s:Ellipse x="60" y="60" width="80" height="80">
            <s:stroke>                  
                <s:LinearGradientStroke rotation="90">
                    <s:entries>
                        <s:GradientEntry color="white" ratio="0.5"/>
                        <s:GradientEntry color="black" ratio="0.5" />
                    </s:entries>
                </s:LinearGradientStroke>
            </s:stroke>
        </s:Ellipse>

Try the following code:

        <s:Ellipse x="60" y="60" width="80" height="80">
            <s:stroke>                  
                <s:LinearGradientStroke rotation="90">
                    <s:entries>
                        <s:GradientEntry color="white" ratio="0.5"/>
                        <s:GradientEntry color="black" ratio="0.5" />
                    </s:entries>
                </s:LinearGradientStroke>
            </s:stroke>
        </s:Ellipse>
最冷一天 2024-08-23 05:58:44

Take a look at Degrafa.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文