条件颜色更改< s:SolidColor& gt; [英] Conditional color change <s:SolidColor>

查看:65
本文介绍了条件颜色更改< s:SolidColor& gt;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于包含基于data.Bld_Type值的if语句的函数,我无法使DataGridItemRenderer将颜色值传递给< s:SolidColor .下面的代码.我对Flex还是陌生的,不知道是什么问题,或者这是否是正确的解决方法.任何帮助,将不胜感激.我尝试传递一个十六进制数字和颜色名称.都不起作用.谢谢.

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>

推荐答案

尝试更改以下内容:

[Bindable]
private var swatchCOL:uint;

并且:

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

最后更改颜色类型:

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

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

这篇关于条件颜色更改&lt; s:SolidColor&amp; gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆