2011-06-07 10 views
5

एसडीके 4.1 का उपयोग करके मैं एक कस्टम त्वचा से कस्टम बटन घटक के कस्टम गुणों तक पहुंचने में सक्षम था। जिस परियोजना में मैं वर्तमान में काम कर रहा हूं उसे एसडीके 4.5 की आवश्यकता है और मैं गुणों तक पहुंचने में असमर्थ हूं। यहाँ एक उदाहरण है:मेजबान कॉम्पोनेंट की कस्टम प्रॉपर्टी एक्सेस करना जब स्किनिंग - फ्लेक्स 4.5, एसडीके 4.5

कस्टम बटन घटक

<?xml version="1.0" encoding="utf-8"?> 
<s:ButtonBase xmlns:fx="http://ns.adobe.com/mxml/2009" 
      xmlns:s="library://ns.adobe.com/flex/spark" 
      xmlns:mx="library://ns.adobe.com/flex/mx" 
      skinClass="components.skins.ButtonIcon_Skin" 
      > 
    <fx:Declarations> 
     <fx:String id="iconCustom" /> 
    </fx:Declarations> 
</s:ButtonBase> 

कस्टम बटन त्वचा

<?xml version="1.0" encoding="utf-8"?> 
<s:SparkButtonSkin xmlns:fx="http://ns.adobe.com/mxml/2009" 
      xmlns:s="library://ns.adobe.com/flex/spark" 
      xmlns:fb="http://ns.adobe.com/flashbuilder/2009" 
      minWidth="21" minHeight="21" 
      alpha.disabled="0.5"> 
    <fx:Metadata>[HostComponent("components.ButtonIcon")]</fx:Metadata> 

... 

    <s:Label id="test" {hostComponent.iconCustom}" 
      horizontalCenter="0" bottom="10" /> 

</s:SparkButtonSkin> 

कोड संकेत hostComponent.iconCustom से पता चलता है, लेकिन फिर त्रुटि देता है:

Access of possibly undefined property iconCustom through a reference with static type spark.components.supportClasses:ButtonBase. ButtonIcon_Skin.mxml 

उत्तर

8

बस एक नियमित रूप से त्वचा के साथ कि SparkButtonSkin की जगह और तुम सिर्फ ठीक हो जाओगे:

<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009" 
     xmlns:s="library://ns.adobe.com/flex/spark"> 

    <fx:Metadata> 
     [HostComponent("components.ButtonIcon")] 
    </fx:Metadata> 

    <s:states> 
     <s:State name="disabled" /> 
     <s:State name="down" /> 
     <s:State name="over" /> 
     <s:State name="up" /> 
    </s:states> 

    <s:Label text="test {hostComponent.iconCustom}" 
      horizontalCenter="0" bottom="10" /> 

</s:Skin> 
+0

आप एक हीरे हैं। एक इलाज किया। – Trist

+1

'' का उपयोग करके संकलन त्रुटियों को भी हटा दिया गया। हालांकि, मुझे लगता है कि दोनों समाधान बटन बार में सेट की गई छवि को प्रदर्शित नहीं करते हैं (जबकि '' इस छवि को संरक्षित करता है। सुनिश्चित नहीं है क्यों)। – ggkmath

+0

क्यों? यहां क्यों नहीं है। अगर मुझे 'स्पार्कबटन स्किन' या कुछ चाहिए तो क्या होगा? क्या हम और स्पष्टीकरण प्राप्त कर सकते हैं? मैं जवाब का पुराना जानता हूं, लेकिन हम यही करते हैं, है ना? – deltree

2

एक अन्य विकल्प है, तो आप SparkButtonSkin उपयोग करना चाहते हैं, बस अपने वास्तविक hostComponent लिए डाली

(hostComponent as ButtonIcon).iconCustom 

या में संदर्भ:

कस्टम बटन त्वचा

<?xml version="1.0" encoding="utf-8"?> 
<s:SparkButtonSkin xmlns:fx="http://ns.adobe.com/mxml/2009" 
      xmlns:s="library://ns.adobe.com/flex/spark" 
      xmlns:fb="http://ns.adobe.com/flashbuilder/2009" 
      minWidth="21" minHeight="21" 
      alpha.disabled="0.5"> 
    <fx:Metadata>[HostComponent("components.ButtonIcon")]</fx:Metadata> 

... 

    <s:Label id="{(hostComponent as ButtonIcon).iconCustom}" 
      horizontalCenter="0" bottom="10" /> 

</s:SparkButtonSkin> 
+0

यदि मैं इस कास्ट को जोड़ता हूं, तो संकलन त्रुटि दूर हो जाती है लेकिन चेतावनी के साथ प्रतिस्थापित किया जाता है "डेटा बाध्यकारी" hostComponent "को असाइनमेंट का पता लगाने में सक्षम नहीं होगा। मैं इस चेतावनी के साथ चला सकता हूं, लेकिन होस्ट से प्राप्त मूल्यों कॉम्पोनेंट गुण हैं अमान्य। – Tony

+0

आपके उत्तर टॉमी के लिए बहुत बहुत धन्यवाद। RIAstar ने मेरे लिए काम नहीं किया, क्योंकि मुझे छवियों को दिखाने के लिए किसी भी तरह स्पार्कबटनस्किन की आवश्यकता थी। आपका जवाब काम करता था। – ggkmath