我有一个简单的疑问。我制作了一个定制的ActionScrip mxml组件,它是一个带有文本区域的Spark标题窗口,如果它在文本中发现‘Success’这个词,则标题(标题栏)应该显示绿色背景,如果没有,则显示红色。
我的问题是我不知道在哪里访问和修改这个属性,我发现的唯一改变是将标题窗口的‘chromeColor’绑定到一个布尔值上,这个布尔值将根据我是否找到‘Success’这个词而改变。这确实会将标题栏背景更改为我想要的颜色,但是,它也会更改滚动条的颜色,例如,这有点恶心。我的类的代码如下:
<?xml version="1.0" encoding="utf-8"?>
<s:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="400"
title="Output: "
chromeColor="{success ? ( 0x00ff6b as uint) : ( 0xFF0000 as uint)}"
close="closeHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.CloseEvent;
import mx.managers.PopUpManager;
[Bindable]
public var success:Boolean = false;
public function setText(text:String):void
{
textContainer.text = text;
if(text.indexOf("SUCCESS")!=-1)
{
success=true;
}
}
protected function closeHandler(event:CloseEvent):void
{
PopUpManager.removePopUp(this);
}
]]>
</fx:Script>
<s:TextArea id="textContainer" x="0" y="0" width="100%" height="100%"
paddingBottom="10" paddingLeft="10" paddingRight="10" paddingTop="10"
borderVisible="false" editable="false" fontFamily="Courier New"/>
</s:TitleWindow>
因此,感谢您的阅读,并希望有人知道答案:)
干杯,辣椒酱
3条答案
按热度按时间chhkpiq41#
如果使用FlashBuilder,请创建一个从要覆盖的外观类型派生的新MXML外观(最好使用名为
skins
的包)。然后创建一个新的ActionScript类并扩展MXML外观。然后,您将完全控制皮肤,并能够在必要时扩展模板。在我的例子中,我想覆盖
TitleWindow``[spark.skins.spark.TitleWindowSkin]
的外观(即使在移动设备上也是如此)。许多对话框项目(即标题栏)不是可换肤的,而是硬编码的。tbFill
是标题栏的ID。我能够调整皮肤代码以将ID属性名称分配给标题栏渐变,并读取样式值来设置颜色[在updateDisplayList
函数中]。然后使用自定义外观类的名称作为要设置外观的项的skinClass
属性。总的来说,使用这种方法并不难做到这一点。这是皮肤类。
在派生的MXML皮肤中:
bvuwiixz2#
我会通过扩展标准组件和创建自定义皮肤来解决这个问题。
我的组件版本:
蒙皮(基于标准蒙皮):
这款简单的应用程序可以测试:
x759pob23#
要做到这一点,Flex4的方法是通过复制TitleWindowSkin的代码来创建您自己的自定义皮肤类,并将其更新为绿色背景。然后,您可以通过将skinClass属性添加到TitleWindow标记或通过在css配置中设置skinClass来告诉Felx使用您的自定义皮肤。