Runtime icons for Flex components

Bitmap or BitmapData can not be used as icon in Flex components like MX Button because they want Class that will instantiate as BitmapAsset.


Create cache of special classes. Each of them will be able to become an icon. Here is that can be used the next way:

  1. var bitmapData:BitmapData = new BitmapData(100, 100);
  2. bitmapData.perlinNoise(100, 100, 3, 10, true, true);
  3. var icon:Class = RuntimeBitmapAsset.getClass(bitmapData);
  4. button.setStyle("icon", icon);

P.S.: The same for DisplayObject-s

The same method can be used to wrap any DisplayObject into Class.

3 responses to “Runtime icons for Flex components”

  1. I think, this would be cooler if we figure out how to generate classes ( via ByteArray, Loader.loadBytes ) in runtime.

  2. [...] Change font size in the whole app with Ctrl+/- Runtime icons for Flex components [...]

  3. That was pretty helpful! Specifically my case was to load icons for nodes of a Tree at runtime.


Leave a Reply