2012-10-04 52 views
0

使用Alpha填充創建矩形時出現問題。看起來像UIComponent不允許填充矩形的「Alpha」,並將其轉換爲100%alpha(alpha = 1)。如何在flex的UIComponent中創建一個用alpha填充的矩形?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時工作。

+0

的Flex 3(MX)或4(火花)? – RIAstar

+1

嘗試使用'addChild(uic);'而不是'addElement(uic);' – loxxy

+0

flex 4 spark。所以不能使用addchild(uic) –

回答

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> 
+0

謝謝。這就像一個魅力! :) –