【问题标题】:Using image while creating custom components in flex在 flex 中创建自定义组件时使用图像
【发布时间】:2011-04-03 17:44:56
【问题描述】:

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

【问题讨论】:

    标签: actionscript-3 air flex4 custom-component


    【解决方案1】:

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

    [Bindable]
    public var path:String;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-21
      • 2011-06-01
      • 2012-01-06
      • 1970-01-01
      • 2012-10-07
      • 1970-01-01
      • 2010-10-23
      相关资源
      最近更新 更多