IconUtility Component for Dynamic Run-Time Icons
I’ve seen a number of emails on the flexcoders mailing list and even a few blog posts that are asking a very specific question: “How do you use run-time loaded images as the icon for buttons, containers, and related components?”. The answer they’ve gotten so far is that you can’t, at least not without creating a lot of custom components. The icon styles built into the Flex framework were only intended for embedded graphics. Although internally they can work with almost any DisplayObject as the icon, the styles and properties themselves are typed as Class. So how can you turn a DisplayObject into a Class?
To be honest, I hit my head against the wall on this one for a handful of evenings. In the end I came up with two workable solutions. Arguably the cleanest way would be to take the run-time loaded graphics, dynamically generate the bytes for a swf which contains that image as a BitmapAsset, and then load the swf to retrieve the generated Class. This would allow you to assign an honest to goodness BitmapAsset Class to the icon property. The problem I had with this method is that it wouldn’t be very easy for developers to use. Even if I created a class to generate the swf from a Loader, there would be some ActionScript involved for the developer to wait for the swf to be loaded and assign the resulting class to the right place. After thinking it through, I decided not to implement this solution. Instead, I found a way to turn the original question on it’s head.
After stepping through the code that handles the icon assignment a few times, I realized the original question, “How can you turn a DisplayObject into a Class?” should really be phrased “How can you reference a Class which displays the right DisplayObject when instantiated?”. This is an easier problem to solve. For my first attempt, I’ve created the IconUtility class. It includes a static method which accepts a url and a component reference, then returns a reference to the IconUtility class itself (which happens to extend BitmapAsset). When the class is instantiated, it will use the information you have passed in to determine which image should be displayed. I’ve decided to release it through my blog for now, since it is still unpolished and a bit of a hack.
<mx:Button id="example" label="Example" icon="{IconUtility.getClass(example, 'http://www.exampledomain.com/image.jpg')}" />
Example: IconAssociations
Download: IconUtility Class (302 kb)
http://blog.benstucki.net/?p=42
分享到:
相关推荐
PaddleTS 是一个易用的深度时序建模的Python库,它基于飞桨深度学习框架PaddlePaddle,专注业界领先的深度模型,旨在为领域专家和行业用户提供可扩展的时序建模能力和便捷易用的用户体验。
白色大气风格的乐器爱好者网站模板下载.zip
海外派遣员工管理守则
flowable-demo-master
内容概要:本文档详细介绍了一个图书馆管理系统的数据库课程设计。内容涵盖需求分析、数据库设计、SQL实现、前端实现及系统测试等环节。项目旨在支持图书借阅、归还、图书信息管理、用户管理等功能。数据库设计包括三个主要表:用户表(Users)、图书表(Books)和借阅记录表(BorrowRecords)。通过具体示例演示了表的创建、数据插入及查询操作。 适用人群:适合正在学习数据库设计或从事数据库相关工作的学生和技术人员。 使用场景及目标:①学习如何进行需求分析,确定系统的功能和数据需求;②掌握数据库设计方法,绘制ER图并转换为具体的表结构;③编写SQL语句,实现数据的增删改查操作;④实现前端页面,完成与后端的交互;⑤进行系统测试,确保各项功能正常运行。 其他说明:此文档不仅提供了理论知识,还给出了详细的代码示例,非常适合动手实践。建议在学习过程中结合文档中的示例,动手实现数据库设计、SQL操作和前端页面,从而加深对数据库技术的理解。
白色风格的手机网站模板下载.rar
白色淡雅风的商务企业网站模板下载.zip
白色大气风格的企业站通用整站网站源码下载.zip
PCle AI加速卡在医疗影像诊断中的应用.docx
Matlab领域上传的视频均有对应的完整代码,皆可运行,亲测可用,适合小白; 1、代码压缩包内容 主函数:main.m; 调用函数:其他m文件;无需运行 运行结果效果图; 2、代码运行版本 Matlab 2019b;若运行有误,根据提示修改;若不会,私信博主; 3、运行操作步骤 步骤一:将所有文件放到Matlab的当前文件夹中; 步骤二:双击打开main.m文件; 步骤三:点击运行,等程序运行完得到结果; 4、仿真咨询 如需其他服务,可私信博主; 4.1 博客或资源的完整代码提供 4.2 期刊或参考文献复现 4.3 Matlab程序定制 4.4 科研合作
白色大气简洁的时装模特企业网站模板下载.zip
西门子PLC 1214C 做的压机控制 可以在触摸屏上任意编辑压装逻辑 该程序为一台设备的完成程序 包含很多工能块 压机控制程序+汇川PN伺服块+脉冲控制块+以太网TCP功能块 + 气缸块+托盘坐标计算块+基恩士扫码器SR1000块+模拟量功能块 所有功能块都是基于模块话编程思路编辑功能块都是SCL语言 可移植性强 一个公式套用所有功能块 可以直接将IO引脚做成触摸屏库关联 编写思路新颖,有助于提高编程能力
通过分析,了解谷歌应用商店app的总体情况。
“开学第一课”小学儿童教育家长会宣传模板
内容概要:本文涵盖了大地测量的基本概念、任务和特点,大地测量系统与参考框架,常用坐标系及其转换方法,传统大地控制网的布设原则,光学经纬仪和全站仪的使用与检验,水平角和三角高程测量的观测方法,以及导线测量的技术要点。文中还提供了多个例题,帮助考生理解和掌握关键知识点。 适合人群:具备一定测绘基础,准备参加注册测绘师资格考试的专业技术人员。 使用场景及目标:用于备考注册测绘师资格考试,提高大地测量领域的专业知识和技能,掌握具体的测量方法和技术细节。 阅读建议:此讲义内容详实,涵盖了大量实用的技术细节,建议结合实际测量工作和练习题进行学习,以加深理解和应用能力。
白色简洁风的设计企业网站模板下载.zip
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于计算机科学与技术等相关专业,更为适合;
白色大气风格的恐龙化石博物馆网站模板下载.zip
白色简洁风格的餐厅会员登录框源码下载.zip
白色创意风格的单反爱好者网站模板下载.zip