0

对于我的基于 AIR 的应用程序,我正在尝试创建一个基于具有图像的画布的自定义组件(如下所示)。

<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 。这使它正常工作,但如果我必须不断更改图像或使用某些异步调用获取图像的路径时,它对我没有帮助。所以,我想知道是否有任何替代方法可以解决这个问题。谢谢!!

4

1 回答 1

1

看起来您只是缺少路径的可绑定元标记。为您的路径声明尝试:

[Bindable]
public var path:String;
于 2010-08-25T14:11:18.113 回答