2011-03-23 224 views
1

我有舞臺上有影片過濾器的影片剪輯。 當我將ColorTransform應用於該影片剪輯時,陰影將被刪除。ColorTransform刪除陰影

 var ct:ColorTransform = new ColorTransform; 
     ct.color = 0x99CC00; 
     lamp.transform.colorTransform = ct; 

如何保存陰影?

+0

難道你不能重新應用DropShadowFilter嗎? – 2011-03-23 16:05:08

+0

'DropShadowFilter'手動設置在flash專業版中。 – Tuco 2011-03-23 16:07:04

回答

2

ColorTransform將轉換整個MovieClip,不幸的是,該過濾器被包括在內。我建議你分層lamp並將變換應用到最頂層,保持底層(陰影)不變。

測試例如:

var ball:Sprite = new Sprite(); 
ball.graphics.beginFill(0x00FF00, 1); 
ball.graphics.drawCircle(50, 50, 50); 
ball.graphics.endFill(); 
ball.filters = [new DropShadowFilter()]; //default black 
ball.addEventListener(MouseEvent.CLICK, changeColor); 
addChild(ball); 

//... 
private function changeColor(evt:MouseEvent):void { 
    var ball:Sprite = evt.target as Sprite; 
    var ct:ColorTransform = new ColorTransform(); 
    ct.color = 0x99CC00; // green-ish 
    ball.transform.colorTransform = ct; 
    ball.filters = [new DropShadowFilter(4, 45, 0xFFFFFF)]; //now white 
} 

即使在投影濾鏡重新應用,你可以看到它仍然將是集科變換綠色十歲上下。

3

的想法是

  1. 節省您的剪輯lamp的過濾器(影子),
  2. 應用轉換,
  3. 把夾在主剪輯和
  4. 重新應用過濾到未轉換的父級。

代碼:

var lampFilters:Array = lamp.filters.slice(); //save filters 

lamp.filters = [];        //empty filters 
var ct:ColorTransform = new ColorTransform(); 
ct.color = 0x99CC00; 
lamp.transform.colorTransform = ct;    //apply your transformation 
var superLamp:Sprite = new Sprite(); 
superLamp.addChild(lamp);      //nest the clip 
addChild(superLamp); 

superLamp.filters = lampFilters;     //re-apply the filters 
1

您應該使用嵌套的顯示對象來實現這個...

比如,你可以創建另一個影片剪輯中的一個影片剪輯。將colortransform應用於內部影片剪輯並將影子應用於外部影片剪輯。對我來說就像是一種魅力:)

1

這是一種不需要父對象的替代方法。基本上使用AdjustColor和ColorMatrix來改變顏色,而不是ColorTransform。

注意:如果您使用的不是Flash之類的IDE,比如Flex或FlashDevelop,則需要將Flash.swc從'Common/Configuration/ActionScript 3.0/libs/flash.swc'包含到您的庫中,用於fl.motion.AdjustColor包/類。你也可以谷歌SWC。

var mc:Sprite = new Sprite(); 
    mc.graphics.beginFill(0xFF0000); 
    mc.graphics.drawCircle(100, 100, 100); 
    mc.graphics.endFill(); 
    addChild(mc); 

    // White out the entire shape first 
    var whiteAC:AdjustColor = new AdjustColor(); 
    whiteAC.brightness = 100; 
    whiteAC.contrast = 100; 
    whiteAC.saturation = -100; 
    whiteAC.hue = 0;    
    var whiteMatrix:Array = whiteAC.CalculateFinalFlatArray(); 
    var whiteCMF:ColorMatrixFilter = new ColorMatrixFilter(whiteMatrix); 

    // Now use ColorMatrixFilter to change color 
    var colorMatrix:Array = hexToMatrix(0x0000FF); 
    var colorCMF:ColorMatrixFilter = new ColorMatrixFilter(colorMatrix); 

    // Create Drop Shadow 
    var myDropShadow:DropShadowFilter = new DropShadow(); 

    mc.filters = [whiteCMF, colorCMF, myDropShadow]; 

    function hexToMatrix (hex:uint, alpha:Number = 1) 
    { 
     var r:Number = ((hex & 0xFF0000) >> 16); 
     var g:Number = ((hex & 0x00FF00) >> 8); 
     var b:Number = ((hex & 0x0000FF)); 

     var matrix:Array = []; 
     matrix = matrix.concat([r, 0, 0, 0, 0]); // red 
     matrix = matrix.concat([0, g, 0, 0, 0]); // green 
     matrix = matrix.concat([0, 0, b, 0, 0]); // blue 
     matrix = matrix.concat([0, 0, 0, alpha, 0]); // alpha 
     return matrix; 
    }