【发布时间】:2026-02-12 04:10:01
【问题描述】:
虽然将 [Style ...] 元数据标记添加到我的子类确实使属性 showPromptWhenFocused 可从 MXML 访问,但 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();
}
}
有什么想法吗?
【问题讨论】:
标签: actionscript-3 apache-flex styles flex4 custom-component