Flex 3:是否可以使用远程图像作为 LinkButton 的图标?
我们正在以编程方式创建 LinkButton,并希望将其图标设置为从远程服务器检索到的图像,而不是嵌入到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我认为您不需要尝试设置样式,而是需要更改保存图标的子对象。 您可以通过以下方式访问它:
用加载器中的位图数据替换其中的位图数据应该很容易。
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:
It should be easy to replace the bitmapData in there with the one from a Loader.
如果没记错的话,您需要使用
button.setStyle('icon', img)
,其中img
是通过Loader
加载的图像班级。If memory serves, you'll want to use
button.setStyle('icon', img)
, whereimg
is an image loaded viaLoader
class.对于拉阿尔托来说,
这可能是一个太晚的答案,但有人可能会发现它有用或作为解决您的问题的起点。 您是否尝试过将图像图标作为类引用? 我不知道这是否适用于动态 URL 中的图像,但这对我有用:
然后在您的代码中:
请参阅此处的示例:
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:
Then in your code:
See this example here:
http://blog.flexexamples.com/2008/09/03/setting-the-icon-on-a-linkbutton-control-in-flex/
http://blog.benstucki.net/?p=42
http://blog.benstucki.net/?p=42
为什么不直接将 mx:Image 的 buttonMode 设置为 true 然后添加单击事件?
我不确定如果不使用带有 linkButton 的嵌入图像是否可能
这 可能值得 在 AS3 中读取
编辑...:
Why not just set the buttonMode of a mx:Image to true then add a click event?
I'm not sure its possible without using an embedded images with a linkButton
This might be worth a read
Edit... in AS3: