2010-05-15 43 views

回答

4

調查ColorTransform。所有DisplayObject(即Sprite,MovieClip,Shape等)都有一個名爲transform的屬性,該屬性又包含一個名爲ColorTransform的屬性。

下面的代碼使得它如此用黑色填充顏色的方形改爲綠色:

 
var square:Shape = new Shape(); 
square.graphics.beginFill(0x000000); 
square.graphics.drawRect(0, 0, 200, 200); 

var ct:ColorTransform = square.transform.colorTransform; 
ct.color = 0x00FF00; 
square.transform.colorTransform = ct; 

addChild(square); 
+0

謝謝您的回答。我的按鈕(每個按鈕都有獨特的形狀)。有沒有更改按鈕的fillColor的方法。 – Win 2010-05-15 19:08:12

+1

如果當你說按鈕意味着fl.controls.Button,那麼提供的答案將工作。事實上,如果你可以*在Flash中看到*屏幕上的東西,那麼它具有* transform *屬性,該屬性又具有* colorTransform *屬性... – heavilyinvolved 2010-05-16 03:59:25

+0

每個按鈕都是單個映射。我從Illustrator導入到閃存庫,並將它們轉換爲按鈕(它們不是矩形)。現在,我手動更改每個縣的顏色。我發現我無法在代碼中更改按鈕的填充顏色,除非將這些按鈕轉換爲影片剪輯。謝謝你的答案;真的很喜歡它! – Win 2010-05-19 04:24:18