IconUtility Component for Dynamic Run-Time Icons

本文探讨了如何在Flex中使用运行时加载的图像作为按钮和其他组件的图标。通过创建IconUtility类,可以将运行时获取的图像用作图标,解决了Flex框架中原生不支持此功能的问题。

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)

 

 

link:  http://blog.benstucki.net/?p=42

git commit -m "数据库配置页面" > TOOL@5.2.0 lint-staged /Users/10280281/growth-qa-front > lint-staged ✔ Preparing lint-staged... ⚠ Running tasks for staged files... ❯ .lintstagedrc — 5 files ❯ *.{md,json} — 2 files ✖ prettier --cache --write [ENOENT] ↓ *.{css,less} — no files ↓ *.{js,jsx} — no files ❯ *.ts?(x) — 2 files ✖ npx @shined/doctor [KILLED] ◼ eslint --fix ◼ prettier --cache --parser=typescript --write ↓ Skipped because of errors from tasks. ✔ Reverting to original state because of errors... ✔ Cleaning up temporary files... ✖ prettier --cache --write failed without output (ENOENT). ✖ npx @shined/doctor failed without output (KILLED).  ELIFECYCLE  Command failed with exit code 1. husky - pre-commit script failed (code 1) 帮我看下到底为什么 这是我的{ "name": "TOOL", "version": "5.2.0", "private": true, "description": "用增测试工具", "repository": { "type": "git", "url": "" }, "license": "ISC", "author": "SHEIN UGrowth", "scripts": { "analyze": "cross-env ANALYZE=1 max build", "build": "NODE_ENV=production sh build.sh", "build:gray": "cross-env UMI_ENV=igray max build", "build:prod": "cross-env UMI_ENV=iprod max build", "build:test": "cross-env UMI_ENV=itest max build", "dev": "pnpm run start:dev", "doctor": "npx @shined/doctor", "format": "prettier --cache --write .", "i18n-remove": "pro i18n-remove --locale=zh-CN --write", "postinstall": "max setup", "lint": "pnpm run postinstall && pnpm run lint:js && pnpm run lint:style && pnpm run lint:prettier && pnpm run tsc", "lint-staged": "lint-staged", "lint:fix": "eslint --fix --cache --ext .js,.jsx,.ts,.tsx && pnpm run lint:style", "lint:js": "eslint --cache --ext .js,.jsx,.ts,.tsx", "lint:prettier": "prettier -c --write \"src/**/*\" --end-of-line auto", "lint:style": "stylelint --fix \"src/**/*.less\" --syntax less", "openapi": "UMI_ENV=openapi max openapi", "playwright": "playwright install && playwright test", "prepare": "husky", "prettier": "prettier -c --write \"src/**/*\"", "serve": "umi-serve", "start": "cross-env REACT_APP_ENV=local UMI_ENV=dev max dev", "start:dev": "cross-env REACT_APP_ENV=dev MOCK=none UMI_ENV=dev max dev", "start:no-mock": "cross-env MOCK=none UMI_ENV=dev max dev", "start:no-ui": "cross-env UMI_UI=none UMI_ENV=dev max dev", "start:pre": "cross-env REACT_APP_ENV=pre UMI_ENV=dev max dev", "start:test": "cross-env REACT_APP_ENV=test MOCK=none UMI_ENV=dev max dev", "test": "max test", "test:component": "max test ./src/components", "test:e2e": "node ./tests/run-tests.js", "tsc": "tsc --noEmit" }, "dependencies": { "@ant-design/icons": "4.8.3", "@ant-design/moment-webpack-plugin": "^1.0.0", "@ant-design/pro-components": "2.8.7", "@arco-design/web-react": "^2.66.5", "@dnd-kit/core": "^6.3.1", "@dnd-kit/sortable": "^10.0.0", "@dnd-kit/utilities": "^3.2.2", "@monaco-editor/react": "^4.7.0", "@shein-components/avatar-robot": "^1.1.3", "@shein-components/rule-graph": "^0.0.2", "@shein-ugrowth/dynamic-modules": "4.1.15", "@shein-ugrowth/game-dejavu": "^0.1.9", "@umijs/max": "^4.4.10", "@umijs/max-plugin-openapi": "^2.0.3", "@umijs/plugins": "^4.4.10", "@umijs/preset-umi": "^4.0.48", "antd": "5.25.1", "big.js": "^6.2.1", "classnames": "^2.3.0", "cross-env": "7.0.0", "cross-port-killer": "^1.3.0", "dom-to-image-more": "^3.6.0", "eslint": "^9.27.0", "form-render": "^2.4.8", "husky": "^9.1.7", "jiti": "^2.4.2", "lint-staged": "^13", "lodash-es": "^4.17.21", "mockjs": "^1.1.0", "moment": "^2.30.1", "prettier": "^3.5.3", "prettier-plugin-organize-imports": "^3.2.2", "prettier-plugin-packagejson": "^2.4.3", "qrcode.react": "^3.1.0", "query-string": "^8.2.0", "rc-menu": "^9.16.1", "react": "^18.2.0", "react-color": "^2.19.3", "react-dom": "^18.2.0", "react-helmet-async": "^1.2.0", "react-quill": "^2.0.0", "react-redux": "^8.1.3", "rrc-loader-helper": "^9.2.1", "sheinq": "^2.0.28", "swagger-ui-dist": "^5.21.0", "typescript": "^5.8.3", "xss": "^1.0.15" }, "devDependencies": { "@playwright/test": "^1.17.0", "@shined/doctor": "^0.0.50", "@shined/eslint": "^0.0.0-snapshot.13", "@types/big.js": "^6.2.2", "@types/express": "^4.17.0", "@types/history": "^4.7.0", "@types/jest": "^26.0.0", "@types/lodash-es": "^4.17.12", "@types/react": "^18.3.21", "@types/react-color": "^3.0.11", "@types/react-dom": "^18.3.7", "@types/react-helmet": "^6.1.0", "eslint": "^9.34.0", "prettier": "^3.6.2", "typescript": "^5.9.2" }, "packageManager": "pnpm@8.15.4", "engines": { "node": ">=12.0.0" }, "pnpm": { "overrides": { "@ant-design/icons": "4.8.3", "@ant-design/pro-components": "2.8.7", "antd": "5.25.1", "rc-tabs": "15.6.1" }, "patchedDependencies": { "@umijs/preset-umi@4.4.10": "patches/@umijs__preset-umi@4.4.10.patch", "rc-tabs@15.6.1": "patches/rc-tabs@15.6.1.patch" } } }
09-10
{ "name": "TOOL", "version": "5.2.0", "private": true, "description": "用增测试工具", "repository": { "type": "git", "url": "" }, "license": "ISC", "author": "SHEIN UGrowth", "scripts": { "analyze": "cross-env ANALYZE=1 max build", "build": "NODE_ENV=production sh build.sh", "build:gray": "cross-env UMI_ENV=igray max build", "build:prod": "cross-env UMI_ENV=iprod max build", "build:test": "cross-env UMI_ENV=itest max build", "dev": "pnpm run start:dev", "doctor": "npx @shined/doctor", "format": "prettier --cache --write .", "i18n-remove": "pro i18n-remove --locale=zh-CN --write", "postinstall": "max setup", "lint": "pnpm run postinstall && pnpm run lint:js && pnpm run lint:style && pnpm run lint:prettier && pnpm run tsc", "lint-staged": "lint-staged", "lint:fix": "eslint --fix --cache --ext .js,.jsx,.ts,.tsx && pnpm run lint:style", "lint:js": "eslint --cache --ext .js,.jsx,.ts,.tsx", "lint:prettier": "prettier -c --write \"src/**/*\" --end-of-line auto", "lint:style": "stylelint --fix \"src/**/*.less\" --syntax less", "openapi": "UMI_ENV=openapi max openapi", "playwright": "playwright install && playwright test", "prepare": "husky", "prettier": "prettier -c --write \"src/**/*\"", "serve": "umi-serve", "start": "cross-env REACT_APP_ENV=local UMI_ENV=dev max dev", "start:dev": "cross-env REACT_APP_ENV=dev MOCK=none UMI_ENV=dev max dev", "start:no-mock": "cross-env MOCK=none UMI_ENV=dev max dev", "start:no-ui": "cross-env UMI_UI=none UMI_ENV=dev max dev", "start:pre": "cross-env REACT_APP_ENV=pre UMI_ENV=dev max dev", "start:test": "cross-env REACT_APP_ENV=test MOCK=none UMI_ENV=dev max dev", "test": "max test", "test:component": "max test ./src/components", "test:e2e": "node ./tests/run-tests.js", "tsc": "tsc --noEmit" }, "dependencies": { "@ant-design/icons": "4.8.3", "@ant-design/moment-webpack-plugin": "^1.0.0", "@ant-design/pro-components": "2.8.7", "@arco-design/web-react": "^2.66.5", "@dnd-kit/core": "^6.3.1", "@dnd-kit/sortable": "^10.0.0", "@dnd-kit/utilities": "^3.2.2", "@monaco-editor/react": "^4.7.0", "@shein-components/avatar-robot": "^1.1.3", "@shein-components/rule-graph": "^0.0.2", "@shein-ugrowth/dynamic-modules": "4.1.15", "@shein-ugrowth/game-dejavu": "^0.1.9", "@umijs/max": "^4.4.10", "@umijs/max-plugin-openapi": "^2.0.3", "@umijs/plugins": "^4.4.10", "@umijs/preset-umi": "^4.0.48", "antd": "5.25.1", "big.js": "^6.2.1", "classnames": "^2.3.0", "cross-env": "7.0.0", "cross-port-killer": "^1.3.0", "dom-to-image-more": "^3.6.0", "form-render": "^2.4.8", "husky": "^9.1.7", "jiti": "^2.4.2", "lint-staged": "^13", "lodash-es": "^4.17.21", "mockjs": "^1.1.0", "moment": "^2.30.1", "prettier-plugin-organize-imports": "^3.2.2", "prettier-plugin-packagejson": "^2.4.3", "qrcode.react": "^3.1.0", "query-string": "^8.2.0", "rc-menu": "^9.16.1", "react": "^18.2.0", "react-color": "^2.19.3", "react-dom": "^18.2.0", "react-helmet-async": "^1.2.0", "react-quill": "^2.0.0", "react-redux": "^8.1.3", "rrc-loader-helper": "^9.2.1", "sheinq": "^2.0.28", "swagger-ui-dist": "^5.21.0", "xss": "^1.0.15" }, "devDependencies": { "@playwright/test": "^1.17.0", "@shined/doctor": "^0.0.50", "@shined/eslint": "^0.0.0-snapshot.13", "@types/big.js": "^6.2.2", "@types/express": "^4.17.0", "@types/history": "^4.7.0", "@types/jest": "^26.0.0", "@types/lodash-es": "^4.17.12", "@types/react": "^18.3.21", "@types/react-color": "^3.0.11", "@types/react-dom": "^18.3.7", "@types/react-helmet": "^6.1.0", "eslint": "^9.34.0", "prettier": "^3.6.2", "typescript": "^5.9.2" }, "packageManager": "pnpm@8.15.4", "engines": { "node": ">=12.0.0" }, "pnpm": { "overrides": { "@ant-design/icons": "4.8.3", "@ant-design/pro-components": "2.8.7", "antd": "5.25.1", "rc-tabs": "15.6.1" }, "patchedDependencies": { "@umijs/preset-umi@4.4.10": "patches/@umijs__preset-umi@4.4.10.patch", "rc-tabs@15.6.1": "patches/rc-tabs@15.6.1.patch" } } } 这是我的package-json, 我的node是18.16.0没看出问题啊
09-10
内容概要:本文提出了一种基于融合鱼鹰算法和柯西变异的改进麻雀优化算法(OCSSA),用于优化变分模态分解(VMD)的参数,进而结合卷积神经网络(CNN)与双向长短期记忆网络(BiLSTM)构建OCSSA-VMD-CNN-BILSTM模型,实现对轴承故障的高【轴承故障诊断】基于融合鱼鹰和柯西变异的麻雀优化算法OCSSA-VMD-CNN-BILSTM轴承诊断研究【西储大学数据】(Matlab代码实现)精度诊断。研究采用西储大学公开的轴承故障数据集进行实验验证,通过优化VMD的模态数和惩罚因子,有效提升了信号分解的准确性与稳定性,随后利用CNN提取故障特征,BiLSTM捕捉时间序列的深层依赖关系,最终实现故障类型的智能识别。该方法在提升故障诊断精度与鲁棒性方面表现出优越性能。; 适合人群:具备一定信号处理、机器学习基础,从事机械故障诊断、智能运维、工业大数据分析等相关领域的研究生、科研人员及工程技术人员。; 使用场景及目标:①解决传统VMD参数依赖人工经验选取的问题,实现参数自适应优化;②提升复杂工况下滚动轴承早期故障的识别准确率;③为智能制造与预测性维护提供可靠的技术支持。; 阅读建议:建议读者结合Matlab代码实现过程,深入理解OCSSA优化机制、VMD信号分解流程以及CNN-BiLSTM网络架构的设计逻辑,重点关注参数优化与故障分类的联动关系,并可通过更换数据集进一步验证模型泛化能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值