[Style ...] メタデータ タグをサブクラスに追加すると、MXML からプロパティshowPromptWhenFocusedにアクセスできるようになりましたが、initializeStyles() 関数はデフォルト値を true に正常に変更しません。
ユーザーが必要に応じてshowPromptWhenFocusedを false に設定できるようにしたいが、デフォルト値を 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();
}
}
何か案は?