2010-08-25 49 views
0

對於基於AIR的應用程序,我嘗試基於具有圖像的畫布創建自定義組件(如下所示)。在flex中創建自定義組件時使用圖像

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100" height="100" cornerRadius="5" borderStyle="solid" borderThickness="2" dropShadowEnabled="true" borderColor="#EDEDE8" dropShadowColor="#dddddd" shadowDistance="5" shadowDirection="center"> 
<mx:Script> 
    <![CDATA[ 
     public var path:String = ""; 
    ]]> 
</mx:Script> 
<mx:Image id="tileImage" maintainAspectRatio="false" buttonMode="true" useHandCursor="true" source="{path}" width="100%" x="0" height="100%" y="0"/> 
<mx:Canvas left="3" top="3" bottom="3" right="3" borderStyle="solid" cornerRadius="5" borderThickness="1" borderColor="#EDEDE8" alpha="0.75"> 
</mx:Canvas> 

我綁定圖像與公衆變量路徑源。當我試圖將這個組件放置在我的主要mxml文件(如下圖)中併爲其提供「路徑」時,我無法在自定義組件中看到任何圖像加載。它仍然是空白的。

var component:MyCustComponent = new MyCustComponent(); 
component.path = 'path/to/image.jpg'; 
addChild(component); 

由於周圍的工作,我想一個creationComplete聽衆在我的自定義組件添加到畫布,用來給titleImage.source = this.path。這使它正常工作,但它不能幫助我,如果我必須不斷改變圖像或使用一些異步調用獲取圖像的路徑。所以,我想知道是否有其他解決方案來解決這個問題。 謝謝!

回答

1

看起來你只是缺少路徑的可綁定元標記。爲您的路徑聲明嘗試:

[Bindable] 
public var path:String; 
+0

感謝好友!那一個工作:) – Goje87 2010-08-26 08:14:15

相關問題