Personally, I’m amazed I can write an entire post around setting a single (and simple) style, but yet here I am. The following example shows how you can place an icon of your choosing in the upper-left corner of a Panel container. As an added bonus, at least I create the Panel in both MXML and ActionScript.
Full code after the jump.
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/08/02/adding-icons-to-panel-containers/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="horizontal"
backgroundColor="white"
applicationComplete="init();">
<mx:Script>
<![CDATA[
[Embed(source='bulletCheck.png')]
private static const ico:Class;
private var panel:Panel;
private function init():void {
var image:Image = new Image();
image.source = "http://www.helpexamples.com/flash/images/image2.jpg";
panel = new Panel();
panel.titleIcon = ico;
panel.title = "Brought to you by ActionScript";
panel.addChild(image);
addChild(panel);
}
]]>
</mx:Script>
<mx:Panel title="Brought to you by MXML" titleIcon="{ico}" id="pan">
<mx:Image id="img" source="http://www.helpexamples.com/flash/images/image1.jpg" />
</mx:Panel>
</mx:Application>
View source is enabled in the following example.





How can I add a toolTip to the titleIcon? Thanks. You’re site has helped me tremendously, keep up the good work….please!
tooltip for titleicon?
Adam,
Not sure if this is the “best” way, but this seems to work (although it does use mx_internal namespace, so I can’t guarantee it will work this way in the future (or in past versions).
Since I don’t have a very high confidence level in this code, I’ll just post it in the comments here instead of making it a new entry.
You may want to try asking on a high volume list, such as FlexCoders and see if you can get any other suggestions. It may be better to extend the Panel class and use an Image control instead of the Bitmap display object. Plus, by extending Panel, you could add a custom parameter (such as titleIconToolTip which would make the code easier to reuse.
Hope that helps,
Peter
Peter,
Thank you for the quick response. Your code worked first time around for me, so thank you for that as well. I will take your advice, I have already posted the question at FlexCoders. I agree best method probably would be extending the Panel. Peter…thanks again.
Hi,
I want to shuffle the panels. Say for Example, if i have two panels that are created at run time using action script. I have one panel after the other in a canvas vertically. If i drag one panel and drop it over the other panel, the dragged panel must be placed on the position where the other panel is and the entire order of panels must get shuffled.
If its confusing, in the above example, if i drag the left panel and drop it over the right panel, the right should come to left and the left panel should come to right.
How can i do this.
Any suggestions or example.
Thanks for the help in advance.
Stranger
Is there any way of getting around embedding the titleIcon and being able to populate it dynamically?
Joel,
Check out Ben Stucki’s IconUtility class at IconUtility Component for Dynamic Run-Time Icons.
Peter