只是一种解决方法
适用于Flex 4.6
基于TextInput组件“skin_password”或类似组件创建新皮肤:
New MXML Skin
现在,在皮肤内部搜索这个(使用一些编辑器,您可以按
,写
文本显示
并按下
进入
):
<s:RichEditableText id="textDisplay" left="1" right="1" top="1" bottom="1"
verticalAlign="middle" widthInChars="12"
left.normal="1" right.normal="1" top.normal="1" bottom.normal="1"/>
添加属性
displayAs密码=true
:
<s:RichEditableText id="textDisplay" left="1" right="1" top="1" bottom="1"
displayAsPassword="true" verticalAlign="middle" widthInChars="12"
left.normal="1" right.normal="1" top.normal="1" bottom.normal="1"/>
搜索此方法:
override protected function initializationComplete():void
{
useChromeColor = true;
super.initializationComplete();
}
添加此行(在我的例子中,是一个黑点,而不是默认的星号*):
textDisplay.mx_internal::passwordChar = "â";
我的皮肤示例在包装中
):
<s:TextInput id="tiPassword" height="30" maxChars="12" skinClass="skins.skin_password" />
现在你有这样的东西:
see working
-
-
再解释一下
当你设置
显示器密码
到
真
,Flex将textFlow添加到TextInput中包含的RichEditableText中,并使用相同数量的“密码字符”。
你可以在代码中看到这一点
RichEditableText.as
:
public function get text():String
{
// Note: if displayAsPassword, _text will contain the actual text and the text flow will
// contain the same number of passwordChars.
// Go to the source if there isn't a pending change. getText has its own buffering and
// only extracts the text from the TextFlow when it is damaged.
if (_textContainerManager && !textChanged && !textFlowChanged && !contentChanged && !displayAsPassword)
return _textContainerManager.getText("\n");
// Extracting the plaintext from a TextFlow is somewhat expensive,
// as it involves iterating over the leaf FlowElements in the TextFlow.
// Therefore we do this extraction only when necessary, namely when
// you first set the 'content' or the 'textFlow'
// (or mutate the TextFlow), and then get the 'text'.
if (_text == null)
{
// If 'content' was last set,
// we have to first turn that into a TextFlow.
if (_content != null)
_textFlow = createTextFlowFromContent(_content);
// Once we have a TextFlow, we can export its plain text.
_text = staticPlainTextExporter.export(
_textFlow, ConversionType.STRING_TYPE) as String;
}
return _text;
}
在功能中
textContainerManager_flowOperationBeginHandler(事件:FlowOperationEvent):无效
if (_displayAsPassword)
{
// Remove deleted text.
if (delLen > 0)
{
_text = splice(_text, delSelOp.absoluteStart,
delSelOp.absoluteEnd, "");
}
// Add in the inserted text.
if (textToInsert.length > 0)
{
_text = splice(_text, insertTextOperation.absoluteStart,
insertTextOperation.absoluteStart, textToInsert);
// Display the passwordChar rather than the actual text.
textToInsert = StringUtil.repeat(passwordChar,
textToInsert.length);
}
}
你可以看到
密码Char
mx内部
/**
* @private
*/
mx_internal var passwordChar:String = "*";