PDA

View Full Version : Dynamic CSSStyleDeclaration


kladrian
08-11-2010, 12:52 PM
Hello everyone

I need to create a new CssStyleDeclaration for a button with only
icons specified; something like this


Button.iconButtonX{
upIcon: Embed(source="resources/images/icons/icon_up.png");
overIcon: Embed(source="resources/images/icons/icon_over.png");
downIcon: Embed(source="resources/images/icons/icon_down.png");
selectedUpIcon: Embed(source="resources/images/icons/icon_sel_up.png");
selectedOverIcon: Embed(source="resources/images/icons/icon_sel_over.png");
selectedDownIcon: Embed(source="resources/images/icons/icon_sel_down.png");
}


but instead of using Embed resources I need to load one (focus on only one , repeated for all) image path

is there any way to do that ?

I've already done this


public static function createNewIconStyle(path:String, styleName:String):void
{
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, _innerLoadComplete);
loader.contentLoaderInfo.addEventListener(IOErrorE vent.IO_ERROR, _innerError);
loader.contentLoaderInfo.addEventListener(Security ErrorEvent.SECURITY_ERROR, _innerError);
loader.load(new URLRequest(path));

function _innerLoadComplete(e:Event):void
{
var ba:BitmapAsset = new BitmapAsset(Bitmap(e.target.content).bitmapData.cl one(),"auto",true);
var bmpIcon:Class = getDefinitionByName(getQualifiedClassName(ba)) as Class;
var style:CSSStyleDeclaration = new CSSStyleDeclaration("."+styleName);
style.setStyle('upIcon', bmpIcon);
style.setStyle('overIcon', bmpIcon);
style.setStyle('downIcon', bmpIcon);
style.setStyle('selectedUpIcon', bmpIcon);
style.setStyle('selectedOverIcon', bmpIcon);
style.setStyle('selectedDownIcon', bmpIcon);
StyleManager.setStyleDeclaration("."+styleName, style, true);
}

function _innerError(e:Event):void
{
trace("NOT LOADED");
}
}



but ofcourse I get nothing and I know why ( I knew it was a long shot :) )

thanks for any help

drkstr
08-17-2010, 02:20 AM
Styles are meant to be static. You can dynamically load a compiled style asset, which contains all the embedded images. Otherwise you will need to implement a proxy pattern to load skin assets at run time.