Sunday, June 28, 2009

Apply Dynamic Style :

We can apply dynamic style using flex movie clip object apply to class and transformation on it.
1) Extend UIComponent and apply transform in it.

package newExtend
{
import flash.geom.ColorTransform;
import mx.core.UIComponent;

public class newSkin extends UIComponent
{
[Embed(source='new/newskin.swf', symbol='appHeader_shade')]
public static const shade:Class;

[Embed(source='new/newskin.swf', symbol='appHeader_sholid')]
public static const solid:Class;

public function newSkin ()
{}

override protected function updateDisplayList(w:Number, h:Number):void
{
super.updateDisplayList(w, h);
if (getStyle("backgroundColor")!=null)
{
var child:Number = this.numChildren;
for (var num:Number=0; num {
this.removeChildAt(0);
}
child = this.numChildren;

var mc_shade:* = new shade();
var mc_solid:* = new solid();
var ct:ColorTransform = mc_shade.transform.colorTransform;
ct.color = getStyle("backgroundColor");
mc_solid.transform.colorTransform = ct;
mc_shade['width'] = w;
mc_shade['height'] = h;
mc_solid['width'] = w;
mc_solid['height'] = h;
this.addChild(mc_solid);
this.addChild(mc_shade);
}
}
}
}

2) In Css Class like.
.NewStyle
{
border-skin: ClassReference("newExtend.newSkin ");
}

3) Action script coding for changing shadow and solid color
var newStyle:CSSStyleDeclaration = StyleManager.getStyleDeclaration(".NewStyle");
if (newStyle.getStyle("backgroundColor")!=color)
newStyle.setStyle("backgroundColor", color);

for any color when we update color in step 3 at that time the color transformation on apply movie clip id done in updateDiplayList.
This method is working from step 3 to 1 when running.

No comments: