2017-03-26 39 views
0

我想樣式使用ActionScript一個Flex 4的GridItem,我曾嘗試以下:的ActionScript 3的setStyle不是一個函數

<mx:VBox 
    height="878" width="1920" 
    xmlns:mx="http://www.adobe.com/2006/mxml" 
    xmlns:s="library://ns.adobe.com/flex/spark" xmlns:local="*" creationComplete="addStyles()"> 


    <mx:Script> 
     <![CDATA[ 


      public var selectedLot:String = ""; 

      private function addStyles():void 
      { 
       testBorder.setStyle("borderThickness", "3"); 
      } 

,但我得到了以下錯誤:

setStyle is not a function.

我錯過了什麼嗎?

GridItem在一箇中繼器內。

這裏是我的GridItem:

<mx:GridItem id="testBorder" width="101" height="52.25" horizontalAlign="center" verticalAlign="middle" borderStyle="solid" borderColor="gray"> 
                      <mx:Image source="assets/ruler-icon.png" /> 
                      <s:Label text="{r.currentItem.sqft}" fontSize="10" color="#808080" fontFamily="Helvetica" /> 
                     </mx:GridItem> 

回答

3

當使用一箇中繼器的GridItem的ID會不一樣。要訪問中繼器內的任何項目,您必須指定與重複項目對應的索引。

舉例:陣列由[「奧迪」,「寶馬」],我們設置這個數組到您的中繼器的數據提供程序,然後進入「奧迪」的電網項目,並設置它的風格,我們必須使用:

testBorder[0].setStyle("borderThickness", "3"); 

此外,重要的一點要考慮,VBox「creationComplete」可以在中繼器完全構建之前執行,因此,調用函數「addStyles」的最佳位置在中繼器的「repeatEnd」事件中,即repeatEnd = 「setTransactionPropertyType()」)。

希望這會有所幫助,

Goodluck。

相關問題