`

IconUtility Component for Dynamic Run-Time Icons

阅读更多
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
分享到:
评论

相关推荐

    react-native-dynamic-vector-icons:react-native-vector-icons包装器以使用动态类型

    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...

    react-dynamic-vector-icons:一组用于React的动态矢量图标

    安装npm run install react-dynamic-vector-icons# oryarn add react-dynamic-vector-icons用法import { CheckBoard , DoubleCheck } from 'react-dynamic-vector-icons' ;export default ( ) =&gt; ( &lt; div&gt; ...

    react-native-vector-icons的简单使用

    在React Native开发中,`react-native-vector-icons`库是一个非常重要的工具,它允许开发者在应用中集成各种高质量的矢量图标。这个库包含了多种图标集,如FontAwesome、Ionicons、Material Icons等,使得UI设计更加...

    material-design-icons-3.0.1.zip

    在"material-design-icons-3.0.1.zip"这个压缩包中,用户可以找到一系列精心设计的图标,这些图标均按照Material Design的准则进行创作。MDI图标库的特点在于其广泛的应用性和灵活性,涵盖了各种类别,如导航、动作...

    react-native-vector-icons,React Native可自定义图标,支持导航栏/选项卡栏/工具栏Android、图像源和完整样式。.zip

    React Native Vector Icons是一款广泛使用的开源库,专门为React Native开发者提供高度可定制的矢量图标。这个库使得在React Native应用中集成图标变得简单且高效,无论是用于导航栏、选项卡栏、工具栏,还是作为...

    element-icons.woff

    element-icons.woff

    gnome-shell-extension-desktop-icons-3.32.1-20.el8_5.1.noarch.rpm

    官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装

    前端项目-webicons.zip

    在“webicons-master”这个压缩包中,我们可以预期找到以下内容: 1. **图标源文件**:可能包含SVG源文件,设计师可以编辑这些文件以自定义颜色、大小或进行其他个性化修改。 2. **预览文件**:通常会有HTML或图片...

    uni-icons.zip

    《uni-icons:深入理解uniapp默认图标库》 在移动应用开发领域,高效、便捷的开发工具至关重要。uni-app作为一款跨平台的开发框架,深受开发者喜爱。它提供了一整套丰富的图标资源,名为“uni-icons”,使得开发者...

    gnome-shell-extension-desktop-icons-3.32.1-20.el8.noarch.rpm

    官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装

    react-native-icons.zip

    在解压后的`react-native-icons-master`文件中,你可能会找到以下内容: 1. `src`目录:包含库的主要源代码,如图标组件的实现。 2. `example`目录:提供了一个示例项目,演示如何在React Native应用中使用这个库。...

    前端项目-angular-material-icons.zip

    在"angular-material-icons-master"这个压缩包中,我们可以预期找到以下文件和目录: 1. `README.md`:项目的基本介绍和使用指南。 2. `src`:源代码目录,可能包含AngularJS指令的实现和其他相关的JavaScript文件...

    TOON-XP Icons

    【TOON-XP Icons】是一套专为提升用户界面视觉体验设计的图标集,其特点在于结合了卡通风格与Windows XP系统的元素,创造出既美观又不失实用性的图标样式。这套图标设计旨在为桌面、文件夹、应用程序等提供个性化且...

    安卓最新开发图标material-design-icons-3.0.1

    安卓最新开发图标material-design-icons-3.0.1,里面包含所有现如今的按合作开发图标,各种dpi

    vue-simple-line-icons-Vuejs的简单线图标组件-Vue.js开发

    :grinning_cat_with_smiling_eyes:SVG-简单线条图标这是简单线条图标的Vue组件,您可以仅通过道具选择SVG或字体图标。...simple-line'Vue.component('simple-line-icons',SimpleLineIcons)或//哟

    react-bootstrap-icons:用于Bootstrap图标的React组件

    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 () {...

    material-design-icons-master.zip

    谷歌官方提供的icon,里面各种不同的icon,不同分辨率下都有

    Bootstrap5 图标库 bootstrap-icons

    Bootstrap5图标库bootstrap-icons是前端开发中一个非常实用的资源,它为开发者提供了大量美观、一致的SVG图标,可以方便地集成到Bootstrap5项目中,为网页设计增添丰富的视觉元素。Bootstrap图标库的设计理念是简洁...

    flat-ui-icons-regular.ttf

    flat-ui-icons-regular.ttf

Global site tag (gtag.js) - Google Analytics