0

形状オブジェクトの配列を含むデータ グリッド テーブルがあります。データ グリッド テーブルの GridColumn は、「MovementLogItemRenderer」というアイテム レンダラーを呼び出します。

私の「MovementLogItemRenderer」には、いくつかのラベルを含む HGroup があります。itemRenderer の data プロパティを使用して、ラベルに表示される特定の情報にアクセスします。

私がやりたいことは、ラベルのテキストの色を制御することです。したがって、 data.shapeColor の値が "purple" に等しい場合、特定のラベルのテキストの色を変更したいと思います。

ファイルを実行しても何も表示されません.UI全体がブラウザに表示されません.

誰かがこれを行う方法を教えてもらえますか? これを行う適切な方法は何ですか?

これは、Data Grid テーブルを含む私の MXML ファイルです。

    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
           creationComplete="createShapes()">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
    <![CDATA[
        import mx.collections.ArrayCollection;
        import mx.controls.Alert;

        [Bindable]
        private var myShapes:ArrayCollection = new ArrayCollection();   

        import FrontEndObjects.Shapes;
        private function createShapes():void{
            var shape1:Shapes = new Shapes();
            shape1.shapeId = "1001";
            shape1.shapeName ="Rec";
            shape1.shapeColor ="pink";                  

            var shape2:Shapes = new Shapes();
            shape2.shapeId = "1002";
            shape2.shapeName ="Cirl";
            shape2.shapeColor ="orange";

            var shape3:Shapes = new Shapes();
            shape3.shapeId = "1003";
            shape3.shapeName ="Trig";
            shape3.shapeColor ="purple";

            myShapes.addItem(shape1);
            myShapes.addItem(shape2);   
            myShapes.addItem(shape3);   
        }

    ]]>
</fx:Script>
<s:DataGrid x="52" y="105" width="378" dataProvider="{myShapes}" requestedRowCount="4">
    <s:columns>
        <s:ArrayList>
            <s:GridColumn dataField="shapedetails" headerText="Shape details" itemRenderer="FrontEndObjects.MovementLogItemRenderer"></s:GridColumn>
            <s:GridColumn dataField="shapeId" headerText="Shape Id"></s:GridColumn>
            <s:GridColumn dataField="shapeName" headerText="Shape Name"></s:GridColumn>
            <s:GridColumn dataField="shapeColor" headerText="Shape Colour"></s:GridColumn>
        </s:ArrayList>
    </s:columns>        
</s:DataGrid>

これは私の「MovementLogItemRenderer」アイテムレンダラーです:

    <s:GridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                xmlns:s="library://ns.adobe.com/flex/spark" 
                xmlns:mx="library://ns.adobe.com/flex/mx" clipAndEnableScrolling="true">    

<fx:Script>
    <![CDATA[   

        [Bindable] public var myTextColour:uint;
        override public function prepare(hasBeenRecycled:Boolean):void {

            super.prepare( hasBeenRecycled );

            if(data.shapeColor == "purple"){
                myTextColour = 0x7a11f1;
            } else {
                myTextColour = 0x000000;
            }
        } 

    ]]>
</fx:Script>    
<s:HGroup>
    <s:Label text="{data.shapeId}"  paddingTop="8"/>    
    <s:Label text="{data.shapeName}"  paddingTop="8"  />    
    <s:Label text="{data.shapeColor}"  paddingTop="8"  color="{myTextColour}" />            
</s:HGroup>

4

1 に答える 1

0

ActionScript の Label の color プロパティは uint で
あるため、この型を使用する必要があります
(#000000 などのカラー コードを使用できるのは MXML でのみ)。ActionScript
プロパティをラベルの色にバインドしているため、使用する必要があります。 uint タイプ また、 itemRenderer
が recled される場合に条件が満たされない場合は、「通常の」色に戻す必要があります。

override public function prepare(hasBeenRecycled:Boolean):void {

            super.prepare( hasBeenRecycled );

            if(data) {
                if(data.shapeColor == "purple"){
                    myTextColour = 0x7a11f1;
                } else {
                    myTextColour = 0x000000;
                }
            }
        } 

あなたの穴のUIが表示されない理由は、コードを追加しないとわかりません.Gridコンポーネントだけで試してみると、あなたの例はうまく動作しています.

于 2013-03-11T11:51:39.257 に答える