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
分享到:
相关推荐
You still need to run this command to link the vector icons' assets # iOS Only npx pod - install 博览会版本: "react-native-dynamic-vector-icons" : "WrathChaos/react-native-dynamic-vector-icons#expo...
安装npm run install react-dynamic-vector-icons# oryarn add react-dynamic-vector-icons用法import { CheckBoard , DoubleCheck } from 'react-dynamic-vector-icons' ;export default ( ) => ( < div> ...
在React Native开发中,`react-native-vector-icons`库是一个非常重要的工具,它允许开发者在应用中集成各种高质量的矢量图标。这个库包含了多种图标集,如FontAwesome、Ionicons、Material Icons等,使得UI设计更加...
在“webicons-master”这个压缩包中,我们可以预期找到以下内容: 1. **图标源文件**:可能包含SVG源文件,设计师可以编辑这些文件以自定义颜色、大小或进行其他个性化修改。 2. **预览文件**:通常会有HTML或图片...
element-icons.woff
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装
在解压后的`react-native-icons-master`文件中,你可能会找到以下内容: 1. `src`目录:包含库的主要源代码,如图标组件的实现。 2. `example`目录:提供了一个示例项目,演示如何在React Native应用中使用这个库。...
在"angular-material-icons-master"这个压缩包中,我们可以预期找到以下文件和目录: 1. `README.md`:项目的基本介绍和使用指南。 2. `src`:源代码目录,可能包含AngularJS指令的实现和其他相关的JavaScript文件...
【TOON-XP Icons】是一套专为提升用户界面视觉体验设计的图标集,其特点在于结合了卡通风格与Windows XP系统的元素,创造出既美观又不失实用性的图标样式。这套图标设计旨在为桌面、文件夹、应用程序等提供个性化且...
:grinning_cat_with_smiling_eyes:SVG-简单线条图标这是简单线条图标的Vue组件,您可以仅通过道具选择SVG或字体图标。...simple-line'Vue.component('simple-line-icons',SimpleLineIcons)或//哟
npm install react-bootstrap-icons --save 要么 yarn add react-bootstrap-icons 用法 import React from ' react ' ; import { ArrowRight } from ' react-bootstrap-icons ' ; export default function App () {...
谷歌官方提供的icon,里面各种不同的icon,不同分辨率下都有
flat-ui-icons-regular.ttf
React Native Vector Icons是一款广泛使用的开源库,专门为React Native开发者提供高度可定制的矢量图标。这个库使得在React Native应用中集成图标变得简单且高效,无论是用于导航栏、选项卡栏、工具栏,还是作为...
在压缩包内的文件"AWS-Architecture-Icons-Deck_For-Light-BG_20190207.pptx"是一个PowerPoint演示文稿,通常包含一套完整的AWS图标集合,适合在浅色背景上使用。这个文件可能包含了不同服务的矢量图,如EC2...
在【压缩包子文件的文件名称列表】中的"weather-icons-master",通常表示这是项目的主分支或源码仓库。打开这个文件夹,我们可以期待找到以下内容: 1. **图标文件**:这些图标可能以.svg、.png或.ttf等格式存在,...
Bootstrap5图标库bootstrap-icons是前端开发中一个非常实用的资源,它为开发者提供了大量美观、一致的SVG图标,可以方便地集成到Bootstrap5项目中,为网页设计增添丰富的视觉元素。Bootstrap图标库的设计理念是简洁...
| | 安装 您应该能够以标准方式安装此软件包,将其... M-x all-the-icons-install-fonts 请记住,这还将在MacOS和Linux上运行fc-cache -f -v ,这可能需要一些时间才能完成。 对于Windows ,此功能将提示您提供下载目