Flex 树控件 - 如何通过 URL 引用图标?
我有一个对象集合,这些对象显示在两个位置 - 空间上作为地图上的图标,以及在树控件中。我想知道是否可以使用用于在树控件中其他位置显示图标的图像 URL。
我尝试简单地使用包含 URL 的字段名称作为树控件上的 iconField,但显然,当 Flex 框架将字符串字段视为图标字段时,它会在包含以下内容的 mxml 文件上查找属性:树的名称与树项上字段的字符串值相同(!?!)。由于我的布局文档没有任何名称类似于“assets/well.png”的字段,因此这会引发错误。
我需要使用图像的 URL 而不是通过嵌入来引用图标,因为客户端需要能够更改图像而无需重新编译。
I have a collection of objects that are displayed in two places - spatially as icons on a map, and in a tree control. I'd like to know if it's possible to use the image URLs that I use for displaying the icons elsewhere in a tree control.
I've tried simply using the name of the field that contains the URL as the iconField on the tree control, but apparently when the flex framework sees a string field as the icon field it looks for a property on the mxml file containing the tree with a name that's the same as the string value for the field on the tree item(!?!). Since my layout documents don't have any fields with names like "assets/well.png", this throws an error.
I need to reference the icons using the URL of the images rather than through embedding, because the client will need to be able to change the image without a recompile.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Tree
setItemIcon
函数(或itemIcons
属性)采用两个Class
对象作为参数。一种可能的解决方案是将 此类 添加到您的项目中,然后使用以下命令动态加载资源的代码:
编辑:
关于 IconUtility 类的原始帖子:http://blog.benstucki.net/?p=42
Tree
setItemIcon
function (oritemIcons
property) takes twoClass
objects as parameters.A possible solution would be to add this class to your project, and then use the following code to dynamically load your assets:
Edit:
Original post about the IconUtility class : http://blog.benstucki.net/?p=42
我尝试构建一个完整的工作示例,并想在这里分享我的经验。这是我的测试代码:
它基于以下示例: http://blog.flexexamples.com/2007/11/15/creating-a-custom-icon-function-on-a-flex-tree-control/
这是我使用的
IconUtility
类:这是来自 Ben 的完整副本Stucki,除了
getClass
函数的target
参数,我将类型从UIComponent
更改为* 如此博客的评论中所建议。
剩下的问题:
如果有人能够阐明这些问题以及如何解决它们,我将不胜感激。
I tried to build a complete working example and want to share my experience here. This is my test code:
It is based on this example: http://blog.flexexamples.com/2007/11/15/creating-a-custom-icon-function-on-a-flex-tree-control/
This is the
IconUtility
class I use with it:This is complete copy from Ben Stucki, except for the
target
argument of thegetClass
function where I changed the type fromUIComponent
to*
as adviced in the comments of this blog.Problems left:
I would be most grateful if somebody could shed some light on those issues and how to fix them.