有条件的颜色变化和LT; S:的SolidColor>有条件、颜色、LT、SolidColor

2023-09-09 21:56:30 作者:待我强大给我媳妇儿一天下

我无法得到为DataGridItemRenderer传递一个颜色值< S:的SolidColor 基于包含功能的if语句根据data.Bld_Type的价值。低于code。我维伊新的Flex和不知道是什么问题,或者如果这是这样做的正确的方式。任何帮助将是AP preciated。我试图传递一个十六进制数字和颜色的名字。无论是工作。谢谢你。

 < XML版本=1.0编码=UTF-8&GT?;
< S:MXDataGridItemRenderer的xmlns:FX =htt​​p://ns.adobe.com/mxml/2009
  XMLNS:S =库://ns.adobe.com/flex/spark
  的xmlns:MX =库://ns.adobe.com/flex/mx
  focusEnabled =真正的>

    < FX:脚本>
        <![CDATA [
         进口mx.events.FlexEvent;

        私人VAR swatchCOL:单元;

        / **彩色功能** /
        私有函数的onLoad():无效
        {
            如果(data.Bld_Type ==办公室)
                {
                swatchCOL =ee7970;
                // *** swatchCOL =红色;

                }
            否则,如果(data.Bld_Type ==办公室/仓库)
                {
                swatchCOL =70b2ee;
                // *** swatchCOL =蓝色;
                }
        }
        ]]≥
    < / FX:脚本>



    &所述氏:组左=10右=10顶端=10底部=10>
        < S:矩形的宽度=25高度=25>
            < S:行程>
                < S:SolidColorStroke颜色=绿色重量=2/>
            < / S:行程>
            < S:补>
                < S:的SolidColor颜色=swatchCOL/>
            < / s的:填入>
        &所述; /秒:矩形>
    < / S:组>



&所述; /秒:MXDataGridItemRenderer>
 

解决方案

尝试改变如下:

  [可绑定]
私人VAR swatchCOL:单元;
 

 < S:补>
    < S:的SolidColor颜色={swatchCOL}/>
< / s的:填入>
 
Color配色小程序

最后变色类型:

 如果(data.Bld_Type ==办公室)
                {
                swatchCOL = 0xee7​​970;
                // *** swatchCOL =红色;

                }
            否则,如果(data.Bld_Type ==办公室/仓库)
                {
                swatchCOL = 0x70b2ee;
                // *** swatchCOL =蓝色;
                }
 

I am unable to get the DataGridItemRenderer to pass a color value to <s:SolidColor based on the function containing an if statement based on the value of data.Bld_Type. Code below. I am vey new to Flex and not sure what the problem or if this is the right way of doing it. Any help would be appreciated. I have tried passing a hex number and color name. Neither work. Thanks.

<?xml version="1.0" encoding="utf-8"?>
<s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
  xmlns:s="library://ns.adobe.com/flex/spark" 
  xmlns:mx="library://ns.adobe.com/flex/mx" 
  focusEnabled="true">

    <fx:Script>
        <![CDATA[
         import mx.events.FlexEvent;

        private var swatchCOL:uint;

        /** color function **/
        private function onLoad():void
        {
            if(data.Bld_Type == "Office")
                {
                swatchCOL="ee7970";
                //***swatchCOL="red";

                }    
            else if(data.Bld_Type == "Office/Warehouse")
                {
                swatchCOL="70b2ee";
                //***swatchCOL="blue";
                }
        }   
        ]]>
    </fx:Script>



    <s:Group left="10" right="10" top="10" bottom="10">
        <s:Rect width="25" height="25">
            <s:stroke>
                <s:SolidColorStroke color="green" weight="2"/>                        
            </s:stroke>
            <s:fill>
                <s:SolidColor color="swatchCOL"/>
            </s:fill>
        </s:Rect>
    </s:Group>



</s:MXDataGridItemRenderer>

解决方案

Try to change the following:

[Bindable]
private var swatchCOL:uint;

And:

<s:fill>
    <s:SolidColor color="{swatchCOL}"/>
</s:fill>

And finally change color types:

if(data.Bld_Type == "Office")
                {
                swatchCOL=0xee7970;
                //***swatchCOL="red";

                }    
            else if(data.Bld_Type == "Office/Warehouse")
                {
                swatchCOL=0x70b2ee;
                //***swatchCOL="blue";
                }