Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 08-11-2010, 12:52 PM   #1
kladrian
Member
 
Join Date: Nov 2008
Posts: 42
Default Dynamic CSSStyleDeclaration

Hello everyone

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

Code:
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

Code:
public static function createNewIconStyle(path:String, styleName:String):void
{
	var loader:Loader = new Loader();
	loader.contentLoaderInfo.addEventListener(Event.COMPLETE, _innerLoadComplete);
	loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, _innerError);
	loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, _innerError);
	loader.load(new URLRequest(path));
	
	function _innerLoadComplete(e:Event):void
	{
		var ba:BitmapAsset = new BitmapAsset(Bitmap(e.target.content).bitmapData.clone(),"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
kladrian is offline   Reply With Quote
Old 08-17-2010, 02:20 AM   #2
drkstr
Flexpert
 
drkstr's Avatar
 
Join Date: Sep 2006
Location: Seattle, WA: USA
Posts: 1,587
Default

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.
drkstr is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:08 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.