While adding the [Style ...] metadata tag to my sub-class did make the property showPromptWhenFocused accessible from MXML, the initializeStyles() function does not successfully change the default value to true.
I want the user to be able to set showPromptWhenFocused to false if they want to, but I want the default value to be true.
package com.santacruzsoftware.crafting.controls
{
import mx.core.FlexGlobals;
import mx.styles.CSSStyleDeclaration;
import mx.styles.StyleManager;
import spark.components.TextInput;
[Style(name="showPromptWhenFocused", inherit="yes", type="Boolean")]
public class WatermarkTextInput extends TextInput
{
private static function initializeStyles() : void
{
var style : CSSStyleDeclaration = FlexGlobals.topLevelApplication.styleManager.getStyleDeclaration("showPromptWhenFocused");
if (!style)
style = new CSSStyleDeclaration();
style.defaultFactory = function() : void
{
this.showPromptWhenFocused = true;
}
FlexGlobals.topLevelApplication.styleManager.setStyleDeclaration("showPromptWhenFocused", style, false);
}
//call the static function immediately after the declaration
initializeStyles();
}
}
Any ideas?