« Using mx_internal namespace | Main | I am such a lazy guy.... :( »

Assigning a default style for your custom styles

I was wondering how to assign a default style to my custom style property while developing a custom component. After some search in the Flex Help, I found this solution:

private static var classConstructed:Boolean = classConstruct();

private static function classConstruct():Boolean
{
if (!StyleManager.getStyleDeclaration("titleBackgroundSkin"))
{
// If there is no CSS definition for StyledRectangle,
// then create one and set the default value.
var newStyleDeclaration:CSSStyleDeclaration = new CSSStyleDeclaration();
newStyleDeclaration.setStyle("titleBackgroundSkin", mx.skins.halo.TitleBackground);
StyleManager.setStyleDeclaration("Chat", newStyleDeclaration, true);
}
return true;
}

This might result '1000: Ambiguous reference to setStyle' error, if you are using mx_internal namespace to call the methods declared with 'mx_internal' namespace. To solve that, try calling the method, by explicitly prefixing 'mx_internal::' before the method. Refer my previous post for more information.

TrackBack

TrackBack URL for this entry:
http://www.subbusos.com/cgi-bin/mt-tb.cgi/15

Comments (1)

Aaron:

Just ran into the Ambiguous reference issue you mentioned. Here's an easier fix even though it's a bit of a hack:

Instead of saying:

newStyleDeclaration.setStyle("titleBackgroundSkin", mx.skins.halo.TitleBackground);

use this:

newStyleDeclaration["setStyle"]("titleBackgroundSkin", mx.skins.halo.TitleBackground);

No more namespace issues!

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on July 5, 2007 3:47 PM.

The previous post in this blog was Using mx_internal namespace.

The next post in this blog is I am such a lazy guy.... :(.

Many more can be found on the main index page or by looking through the archives.

Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by
Movable Type 3.34