简体   繁体   English

Flex:如何制作进度条外观?

[英]Flex: how to make progressbar skins?

I wanna set a custom skin on my progressBar, but it's not working out the way I want it to. 我想在我的progressBar上设置自定义外观,但是它无法实现我想要的方式。 My skin has 3 different colors on it (green, yellow, red) and green should show until it's about 50%, then I want the yellow to appear after green and the red at 90% after green and yellow. 我的皮肤上有3种不同的颜色(绿色,黄色,红色),绿色应该显示到大约50%,然后我希望黄色在绿色之后出现,红色在90%之后在绿色和黄色之后出现。 So at 100% they should all show. 因此,它们都应100%显示。

The problem is that the ProgressBar only sets the width of my skin so all colors are showing at all times. 问题在于ProgressBar仅设置我的皮肤宽度,因此所有颜色始终显示。 But if I use the indeterminateSkin but dont set indeterminate to true that doesn't happend. 但是,如果我使用indeterminateSkin但不将indeterminate设置为true,则不会发生。

How can I make a skin that doesn't just change width? 如何制作不仅仅改变宽度的皮肤? Atm I'm just using a MovieClip for a skin. Atm我只是在用MovieClip做皮肤。

I've done this in the past using programmatic skins. 我过去使用程序化皮肤进行了此操作。 You need to create your own versions of ProgressBarSkin and ProgressBarMaskSkin and optionally ProgressBarTrackSkin. 您需要创建自己的ProgressBarSkin和ProgressBarMaskSkin版本,以及可选的ProgressBarTrackSkin版本。 In your ProgressBarSkin, you can override the updateDisplayList method like so: 在您的ProgressBarSkin中,您可以像这样重写updateDisplayList方法:

    override protected function updateDisplayList(w:Number, h:Number):void {
        super.updateDisplayList(w, h);
        graphics.clear();

        var fullWidth:int = w;
        if (parent != null && (parent as UIComponent).mask != null)
            fullWidth = (parent as UIComponent).mask.width;

        var matrix:Matrix = new Matrix();
        matrix.createGradientBox(fullWidth, h);
        var colors:Array = [0xd00000, 0xf0d000, 0x00ff00];

        this.graphics.lineStyle();
        this.graphics.beginGradientFill(GradientType.LINEAR, colors, [1,1,1], [0,128,255], matrix); 
        this.graphics.drawRoundRect(2, 2, w - 4, h - 4, h - 4); 
    }

And in your ProgressBarMaskSkin do this: 然后在您的ProgressBarMaskSkin中执行以下操作:

    override protected function updateDisplayList(w:Number, h:Number):void {
        super.updateDisplayList(w, h);
        graphics.clear();

        this.drawRoundRect(2, 2, w - 4, h - 4, (h - 4) / 2, 0xffffff, 1); 
    }

Then you assign your skin classes to your progress bar and you are set. 然后,将皮肤类别分配到进度栏,然后就可以设置好了。 Hope that helps. 希望能有所帮助。

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

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