Apache flex 使用两个按钮自定义警报框

Apache flex 使用两个按钮自定义警报框,apache-flex,actionscript-3,Apache Flex,Actionscript 3,我需要用两个按钮自定义我的警报框,两个按钮上都需要有不同的皮肤 我能用一张皮做这件事。但我不知道这两张皮是怎么回事 我现在拥有的代码如下: public function Messages():void { Alert.buttonWidth = 100; Alert.yesLabel = "Accept"; Alert.noLabel = "Reject";

我需要用两个按钮自定义我的警报框,两个按钮上都需要有不同的皮肤

我能用一张皮做这件事。但我不知道这两张皮是怎么回事

我现在拥有的代码如下:

public function Messages():void
{   
            Alert.buttonWidth = 100;                            
            Alert.yesLabel = "Accept";
            Alert.noLabel = "Reject";                           
            var alert:Alert = Alert.show("Accept video chat request from "+far_alias+"?", "Incoming Video Chat Request", Alert.YES | Alert.NO | Alert.NONMODAL, Sprite(Application.application), handleIncomingCallResponse, null, Alert.YES);                                                  
            alert.data = cm;
            alert.name = alert_name;
            alert.styleName = "requestVideoAlert"
            _alertDic[alert_name] = alert;

            Alert.yesLabel = "Yes";
            Alert.noLabel = "No";                           
}
<mx:Style>
.requestVideoAlert
{       
    background-color: #000000;
    back-color: #000000;
    area-fill:#000000;
    border-color:#000000;       
    dropShadowEnabled: false;
    button-style-name: cancelbtn;
}
.cancelbtn
{
    skin: Embed(source='assets/images/videoChat-cancel-button.png');
}
Css代码如下所示:

public function Messages():void
{   
            Alert.buttonWidth = 100;                            
            Alert.yesLabel = "Accept";
            Alert.noLabel = "Reject";                           
            var alert:Alert = Alert.show("Accept video chat request from "+far_alias+"?", "Incoming Video Chat Request", Alert.YES | Alert.NO | Alert.NONMODAL, Sprite(Application.application), handleIncomingCallResponse, null, Alert.YES);                                                  
            alert.data = cm;
            alert.name = alert_name;
            alert.styleName = "requestVideoAlert"
            _alertDic[alert_name] = alert;

            Alert.yesLabel = "Yes";
            Alert.noLabel = "No";                           
}
<mx:Style>
.requestVideoAlert
{       
    background-color: #000000;
    back-color: #000000;
    area-fill:#000000;
    border-color:#000000;       
    dropShadowEnabled: false;
    button-style-name: cancelbtn;
}
.cancelbtn
{
    skin: Embed(source='assets/images/videoChat-cancel-button.png');
}

.requestVideoAlert
{       
背景色:#000000;
背面颜色:#000000;
面积填充:#000000;
边框颜色:#000000;
dropShadowEnabled:false;
按钮样式名称:cancelbtn;
}
.取消
{
皮肤:嵌入(source='assets/images/videoChat cancel button.png');
}

这使“接受”和“拒绝”按钮具有相同的外观

谁能帮我一下吗

多谢各位
Zee

不幸的是,我不认为有一种简单的方法可以做到这一点——按钮样式是在AlertForm中设置的,方法是循环遍历警报上的所有按钮,并将其样式名设置为buttonStyleName。为了设置单独的按钮样式,我认为您必须同时扩展Alert(使用自定义AlertForm类)和AlertForm(覆盖styleChanged以指定单独的样式名称)。

不幸的是,我不认为有一种简单的方法可以做到这一点——按钮样式是在AlertForm中设置的,方法是循环遍历警报上的所有按钮,并将其stylename设置为buttonStyleName。为了设置单独的按钮样式,我认为您必须同时扩展Alert(使用自定义AlertForm类)和AlertForm(覆盖样式更改以指定单独的样式名称)。

我不知道您是否已经找到解决方案,但如果没有,并且您使用flex 3,我可以帮助您。 这段代码应该满足您的需要。 更改按钮,甚至更改按钮上文本的样式

"
受保护函数应用程序1\u creationCompleteHandler(事件:FlexEvent):无效
{
initStyles();
var myAlert:Alert=Alert.show(“说明”、“标题”、Alert.YES | Alert.NO”);
var arrOfButtons:Array=myAlert.mx_internal::alertForm.mx_internal::buttons;
var button1:Button=arrOfButtons[0];
var button2:Button=arrOfButtons[1];
//按钮过滤器
button1.styleName='buttonStyle1';
button2.styleName='buttonStyle2';
按钮1.addEventListener(Event.ADDED\u至\u阶段,OnAddedStatage);
}
AddedStatage上的私有函数(事件:事件):void
{
//您也可以更改按钮上的文本
var btn:Button=event.target作为按钮;
变量text:UITextField=btn.getChildAt(0)作为UITextField;
text.filters=[new GlowFilter(0x3946C0,1,4,2,8)];
}
/**
*设置警报移除按钮的样式
**/
私有函数initButton1Style():void
{
var buttonStyle1:CSSStyleDeclaration=新的CSSStyleDeclaration('buttonStyle1');
按钮样式1.设置样式(“fontWeight”,“正常”);
buttonStyle1.setStyle('fontColor',0x000000);
buttonStyle1.setStyle('color',0x000000);
buttonStyle1.setStyle(“填充颜色”[0xffffff,0xF5A2A2,0xF5A2A2,0xffffff]);
按钮样式1.设置样式('fontSize',10);
按钮样式1.setStyle('themeColor',0xff0000);
StyleManager.setStyleDeclaration(“.buttonStyle1”,buttonStyle1,true);
}
/**
*为警报设置购买按钮的样式
**/
私有函数initButton2Style():void
{
var buttonStyle2:CSSStyleDeclaration=新的CSSStyleDeclaration('buttonStyle2');
按钮样式2.设置样式(“fontWeight”,“正常”);
buttonStyle2.setStyle('fontColor',0x000000);
buttonStyle2.setStyle('color',0x000000);
buttonStyle2.setStyle(“填充颜色”[0xffffff,0xBAFFAB,0xBAFFAB,0xffffff]);
按钮样式2.设置样式('fontSize',10);
按钮样式2.设置样式(“颜色”,0x7CCB6C);
StyleManager.setStyleDeclaration(“.buttonStyle2”,buttonStyle2,true);
}
私有函数initStyles():void
{
initButton1Style();
initButton2Style();
}
]]>

我不知道您是否已经找到了解决方案,但如果没有,并且您使用flex 3,我可以帮助您。 这段代码应该满足您的需要。 更改按钮,甚至更改按钮上文本的样式

"
受保护函数应用程序1\u creationCompleteHandler(事件:FlexEvent):无效
{
initStyles();
var myAlert:Alert=Alert.show(“说明”、“标题”、Alert.YES | Alert.NO”);
var arrOfButtons:Array=myAlert.mx_internal::alertForm.mx_internal::buttons;
var button1:Button=arrOfButtons[0];
var button2:Button=arrOfButtons[1];
//按钮过滤器
button1.styleName='buttonStyle1';
button2.styleName='buttonStyle2';
按钮1.addEventListener(Event.ADDED\u至\u阶段,OnAddedStatage);
}
AddedStatage上的私有函数(事件:事件):void
{
//您也可以更改按钮上的文本
var btn:Button=event.target作为按钮;
变量text:UITextField=btn.getChildAt(0)作为UITextField;
text.filters=[new GlowFilter(0x3946C0,1,4,2,8)];
}
/**
*设置警报移除按钮的样式
**/
私有函数initButton1Style():void
{
var buttonStyle1:CSSStyleDeclaration=新的CSSStyleDeclaration('buttonStyle1');
按钮样式1.设置样式(“fontWeight”,“正常”);
buttonStyle1.setStyle('fontColor',0x000000);
buttonStyle1.setStyle('color',0x000000);
buttonStyle1.setStyle(“填充颜色”[0xffffff,0xF5A2A2,0xF5A2A2,0xffffff]);
按钮样式1.设置样式('fontSize',10);
按钮样式1.setStyle('themeColor',0xff0
    mx|Button.alertBtnStyle1 {
        skin: ClassReference("skins.myEmphasizedSkin");
        /* desired style */
    }

    mx|Button.alertBtnStyle2 {
        emphasizedSkin: ClassReference("skins.myButtonDefaultSkin");
        /* desired style */

    }