Spark TextInput 验证上的 errorSkin
我可能正在服用疯狂的药物,但有人真正让 errorSkin 功能发挥作用吗?我没有做任何疯狂的事情,只是扩展 TextInput (spark) 并设置 errorSkin 属性。
我尝试过使用 SparkSkin 创建皮肤,但什么也没做。 我尝试使用 ProgrammaticSkin 创建皮肤,但什么也没做。
TextInput 始终是红色边框。我知道您可以设置 errorColor 和 errorString 但我显然希望做的不仅仅是更改边框的颜色。我正在使用 Flex 4.1 进行编译。
有什么想法吗?
实现:
<components:PromptedTextInput id="txt"
width="200"
horizontalCenter="0"
verticalCenter="0"
errorSkin="skins.TestSkin" />
类
public class PromptedTextInput extends TextInput
{
public function PromptedTextInput()
{
super();
}
}
错误皮肤:
<s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Metadata>
<![CDATA[
[HostComponent("spark.components.TextInput")]
]]>
</fx:Metadata>
<s:states>
<s:State name="normal" />
<s:State name="disabled" />
<s:State name="error" />
</s:states>
<!-- fill -->
<s:Rect id="background"
left="1" right="1" top="1" bottom="1">
<s:fill>
<!--- Defines the background fill color. -->
<s:SolidColor id="bgFill"
color="#66CC66" />
</s:fill>
</s:Rect>
</s:SparkSkin>
另一个错误皮肤尝试:
public class TestSkin extends ProgrammaticSkin
{
public function TestSkin()
{
super();
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
graphics.clear();
graphics.beginFill(0x33CC33);
graphics.drawRect(0, 0, unscaledWidth, unscaledHeight);
graphics.endFill();
}
}
I might be taking crazy pills but has anyone actually gotten the errorSkin feature to work? I am not doing anything crazy, just extending TextInput (spark) and setting the errorSkin property.
I have tried creating a skin using SparkSkin, did nothing.
I have tried creating a skin using ProgrammaticSkin, did nothing.
TextInput is always a red border. I know you can set errorColor and errorString but I am obviously looking to do more than just change the color of the border. I am compiling using Flex 4.1.
Any ideas?
Implimentation:
<components:PromptedTextInput id="txt"
width="200"
horizontalCenter="0"
verticalCenter="0"
errorSkin="skins.TestSkin" />
Class
public class PromptedTextInput extends TextInput
{
public function PromptedTextInput()
{
super();
}
}
Error Skin:
<s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Metadata>
<![CDATA[
[HostComponent("spark.components.TextInput")]
]]>
</fx:Metadata>
<s:states>
<s:State name="normal" />
<s:State name="disabled" />
<s:State name="error" />
</s:states>
<!-- fill -->
<s:Rect id="background"
left="1" right="1" top="1" bottom="1">
<s:fill>
<!--- Defines the background fill color. -->
<s:SolidColor id="bgFill"
color="#66CC66" />
</s:fill>
</s:Rect>
</s:SparkSkin>
Another Error Skin Attempt:
public class TestSkin extends ProgrammaticSkin
{
public function TestSkin()
{
super();
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
graphics.clear();
graphics.beginFill(0x33CC33);
graphics.drawRect(0, 0, unscaledWidth, unscaledHeight);
graphics.endFill();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过基于 \Flex 4.1\frameworks\projects\spark\src\spark\skins\spark\ErrorSkin.as 中找到的 ErrorSkin (不是 TextInput 皮肤)创建皮肤?
Have you tried to create a skin based on the ErrorSkin (not the TextInput skin) found in \Flex 4.1\frameworks\projects\spark\src\spark\skins\spark\ErrorSkin.as ?
嗯,虽然不漂亮,但看起来有两个皮肤需要改变。错误皮肤和焦点皮肤。好消息是您可以使它们相同。对于皮肤,为了测试,我完全复制了 Adobe 的 ErrorSkin 类。遗憾的是,即使将颜色硬编码到皮肤中,我仍然可以在边框的角落看到一个红色像素。如果我修复它,我会尝试更新它。谢谢大家。
UPDATE
听起来很愚蠢,但实际上只是在 ErrorSkin 的 processBitmap() 函数中设置 errorColor 样式。这里我将错误边界硬编码为 0x99CC66
Well, it is not pretty but it looks like there are two skins that have to change. ErrorSkin and FocusSkin. The good news is that you can just make them the same. For the skins, just to test, I just copied Adobe's ErrorSkin class entirely. Sadly, even by hard-coding the color into the skin, I can still see one pixel of red peaking through in the corners of the border. I'll try to update this if I fix it. Thanks all.
UPDATE
Sounds dumb and it prolly is but just set the errorColor style in the ErrorSkin's processBitmap() function. Here I am hard-coding the error border to be 0x99CC66