在 Flex 中创建自定义组件时使用图像

发布于 2024-09-16 13:11:56 字数 1170 浏览 3 评论 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 。这使它可以正常工作,但如果我必须不断更改图像或使用某些异步调用获取图像的路径,这对我没有帮助。所以,我想知道是否有任何替代方法可以解决这个问题。 谢谢!!

For my AIR based application I am trying to create a custom component based on canvas which has an image (as shown below).

<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>

I am binding the source of the image with the public variable path. And when I am trying to place this component in my main mxml file like below and provide the 'path' to it, I am unable to see any image loading in the custom component. It remains blank.

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

As a work around, I am trying to add an creationComplete listener to the canvas in my custom component and used to give titleImage.source = this.path . This made it work correctly but it doesn't help me if I have to keep changing the image or when the path of the image fetched using some async call. So, I would like to know if there's any alternative to fix this problem.
Thanks!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

献世佛 2024-09-23 13:11:56

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

[Bindable]
public var path:String;

Looks like you are just missing the bindable metatag for path. for your path declaration try:

[Bindable]
public var path:String;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文