Flex UIComponent不允许使用“ALPHA”填充创建矩形

时间:2012-10-04 05:58:36

标签: actionscript-3 flex

创建带alpha填充的矩形时遇到问题。似乎UIComponent不允许填充矩形的“Alpha”,并将其转换为100%alpha(alpha = 1)。如何在flex的UIComponent中制作一个填充alpha的矩形?

var uic:UIComponent = new UIComponent(); 


var mc:MovieClip = new MovieClip(); 

mc.graphics.beginFill(0xffcc33,0.2) // <<<<<<NOTICE THE ALPHA FILL
mc.graphics.lineStyle( 1,0xffcc33);
mc.graphics.drawRect(0,0,100,100);
mc.graphics.endFill();
uic.addChild(mc);

addElement(uic);

PS:另外,将动画片段添加到UIComponent时,甚至像“Glow”这样的滤镜效果也不起作用。

1 个答案:

答案 0 :(得分:1)

您可以使用此代码创建带有“ALPHA”填充

的矩形
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               minWidth="955"
               minHeight="600">

    <fx:Script>
        <![CDATA[
        import mx.graphics.SolidColor;
        import mx.graphics.SolidColorStroke;

        import spark.primitives.Rect;

        public function makeRect():void {
            var rect:Rect = new Rect();
            rect.width = 100;
            rect.height = 100;

            rect.fill = new SolidColor(0xffcc33, 0.2);
            rect.stroke = new SolidColorStroke(0xffcc33, 1);

            addElement(rect);
        };
    ]]>
    </fx:Script>

    <s:Button click="makeRect()"/>

</s:Application>