Devel Blog – CoPLaS

Blog about things, I'm currently interested in. Now Flex, Grails and Java.

About me

Developer from Slovak Republic, EU. Currently interested in Java, Grails and Flex.

CV - Curriculum Vitae

I just had a problem with adding icon to a Panel title dynamically. When it is embedded, there is no problem. Than I found IconUtility Component for Dynamic Run-Time Icons and hoped everything will be fine in 5 minutes. I just tried example:

<mx:Button id="example" label="Example"
        icon="{IconUtility.getClass(example, 'http://michal.pavlasek.sk/us.png', 16, 16)}" />



All worked OK, so I tried to set titleIcon property on Panel:

[code lang="actionscript"]

import com.benstucki.utilities.IconUtility;

]]>

titleIcon="{IconUtility.getClass(testIconPanel, 'http://www.pavlasek.sk/devel/us.png', 16, 16)}">



[/code]

…and no icon were displayed.

After a while when I debugged IconUtility I realized that there is Dictionary object used, but problem was that key (in key-value pair) was the UIComponent that has the icon. All is OK for the button, but when used for Panel, the object is not Panel but Panel.titleBar property. Unfortunately it is not public but protected property so it is necessary to extend Panel. Here is example, first panel is just Panel and therefore no icon is in title, second is extended panel – IconPanel, there is one new property: titleIconSrc:String (view source enabled – use right mouse button):

Get Adobe Flash player


[code lang="actionscript"] xmlns:panel="panel.*" viewSourceURL="flex/panelIcon/srcview/index.html">

import com.benstucki.utilities.IconUtility;

]]>

titleIcon="{IconUtility.getClass(testIconPanel, 'http://www.pavlasek.sk/devel/us.png', 16, 16)}">

titleIconSrc="http://www.pavlasek.sk/devel/ico2.png">


[/code]

IconPanel.mxml
[code lang="actionscript"] creationComplete="onCreationComplete()" titleIcon="{ico}">


import com.benstucki.utilities.IconUtility;

[Inspectable]
[Bindable]
public var titleIconSrc:String;

[Bindable]
private var ico:Class;

private function onCreationComplete():void {
ico = IconUtility.getClass(this.titleBar, titleIconSrc, 16, 16);
}

]]>


[/code]

Leave a Reply