Flex 3:是否可以使用远程图像作为 LinkBut​​ton 的图标?

发布于 2024-07-27 16:33:18 字数 724 浏览 3 评论 0原文

我们正在以编程方式创建 LinkBut​​ton,并希望将其图标设置为从远程服务器检索到的图像,而不是嵌入到 SWF 中的图像。 .icon 属性需要一个 Class,但我不知道如何创建一个与 @Embed 等效的类,而是从动态生成的 URLRequest 中创建或 URL 字符串。

var myImage:Image = new Image();
myImage.source = "http://www.domain.com/img/1234.png";
myImage.width = 16;
myImage.height = 16;
myImage.scaleContent = true;

var myButton:LinkButton = new LinkButton();
myButton.label = "Some text"

// This is what I'm trying to figure out.
myButton.setStyle("icon", ???)

我可能遗漏了一些明显的东西 - 我尝试分别传递 URL 和 myImage 但两者都会引发错误。 进入 setStyle() 方法显示代码需要一个 Class - 那么我应该传递什么来代替 ???

我无法嵌入图像本身,因为它是动态的 - 每次软件运行时 URL 都不同。

感谢您的帮助!

We are creating a LinkButton programmatically and would like to set it's icon to an image retrieved from the remote server rather than something embedded within the SWF. The .icon property expects a Class but I can't figure out how to create one equivalent to an @Embed but from a dynamically generated URLRequest or URL String.

var myImage:Image = new Image();
myImage.source = "http://www.domain.com/img/1234.png";
myImage.width = 16;
myImage.height = 16;
myImage.scaleContent = true;

var myButton:LinkButton = new LinkButton();
myButton.label = "Some text"

// This is what I'm trying to figure out.
myButton.setStyle("icon", ???)

I'm probably missing something obvious - I've tried passing in the URL and myImage separately but both throw errors. Stepping into the setStyle() method shows that the code is expecting a Class - so what do I pass in place of the ???

I can't embed the image itself because it's dynamic - the URL is different each time the software runs.

Thanks for any assistance!

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

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

发布评论

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

评论(5

寂寞笑我太脆弱 2024-08-03 16:33:19

我认为您不需要尝试设置样式,而是需要更改保存图标的子对象。 您可以通过以下方式访问它:

Var:Bitmap icon = myButton.getChildByName("upIcon") as Bitmap

用加载器中的位图数据替换其中的位图数据应该很容易。

I think that instead of trying to set the style, you need to change the child object that holds the icon. You can access it by something like:

Var:Bitmap icon = myButton.getChildByName("upIcon") as Bitmap

It should be easy to replace the bitmapData in there with the one from a Loader.

瞳孔里扚悲伤 2024-08-03 16:33:19

如果没记错的话,您需要使用 button.setStyle('icon', img),其中 img 是通过 Loader 加载的图像班级。

If memory serves, you'll want to use button.setStyle('icon', img), where img is an image loaded via Loader class.

笑忘罢 2024-08-03 16:33:19

对于拉阿尔托来说,

这可能是一个太晚的答案,但有人可能会发现它有用或作为解决您的问题的起点。 您是否尝试过将图像图标作为类引用? 我不知道这是否适用于动态 URL 中的图像,但这对我有用:

[Embed("assets/LinkButton.png")]
private const linkButtonIcon:Class;

然后在您的代码中:

myButton.setStyle("icon", linkButtonIcon);

请参阅此处的示例:

http://blog.flexexamples.com/2008/09/03/setting-the-链接上的图标按钮控件 in-flex/

for laalto,

this may be too late of an answer but somebody might find it useful or as a starting point to a solution to your problem. Have you tried referencing your image icon as a class? I don't know if this will work for an image which is in a dynamic URL but this worked for me:

[Embed("assets/LinkButton.png")]
private const linkButtonIcon:Class;

Then in your code:

myButton.setStyle("icon", linkButtonIcon);

See this example here:

http://blog.flexexamples.com/2008/09/03/setting-the-icon-on-a-linkbutton-control-in-flex/

渔村楼浪 2024-08-03 16:33:19
<mx:Button id="example" label="Example" icon="{IconUtility.getClass(example, 'http://www.exampledomain.com/image.jpg')}" />

http://blog.benstucki.net/?p=42

<mx:Button id="example" label="Example" icon="{IconUtility.getClass(example, 'http://www.exampledomain.com/image.jpg')}" />

http://blog.benstucki.net/?p=42

夜司空 2024-08-03 16:33:18

为什么不直接将 mx:Image 的 buttonMode 设置为 true 然后添加单击事件?

<mx:Image source="{imageSource}" buttonMode="true" click="action()" />

我不确定如果不使用带有 linkBut​​ton 的嵌入图像是否可能

可能值得 在 AS3 中读取

编辑...:

var img:Image = new Image();
img.source = "...";
img.buttonMode = true;
img.addEventListenever(MouseEvent.CLICK, funcName);

Why not just set the buttonMode of a mx:Image to true then add a click event?

<mx:Image source="{imageSource}" buttonMode="true" click="action()" />

I'm not sure its possible without using an embedded images with a linkButton

This might be worth a read

Edit... in AS3:

var img:Image = new Image();
img.source = "...";
img.buttonMode = true;
img.addEventListenever(MouseEvent.CLICK, funcName);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文