0

[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();
}
} 

何か案は?

4

2 に答える 2

0

クラスの名前で passを呼び出すとgetStyleDeclaration()、WaterMarkTextInput スタイル宣言を取得できます。

var style : CSSStyleDeclaration = FlexGlobals.topLevelApplication.styleManager.getStyleDeclaration("WatermarkTextInput");

次に、クラスのスタイルを設定するときに同じことを行います。

FlexGlobals.topLevelApplication.styleManager.setStyleDeclaration("WatermarkTextInput", style, false);
于 2012-04-21T18:05:21.183 に答える
0

notifyStyleChangeInChildren()をオーバーライドしてみてください。

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 {

        public var inheritStyles:boolean = true;

        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();

        public override function notifyStyleChangeInChildren(styleProp:String, recursive:Boolean):void {
            if (!inheritStyles) {
                switch(styleProp) {
                    case 'showPromptWhenFocused':
                        return;
                }
            }
            super.notifyStyleChangeInChildren(styleProp, recursive);
        }

}
于 2016-04-07T22:17:01.617 に答える