Take the 2-minute tour ×

I have a Flex tree control that holds a tree full of various types of objects. I'd like to change the label of the item based on this type (and other properties). I'd prefer to do this in a custom TreeItemRenderer rather than via label or labelfunction.

It seems that whatever I do, I cannot typecheck nor cast the objects and thus I get [Object object] in the nodes of my tree. Here is my renderer:

public class MyCustomTreeItemRenderer extends TreeItemRenderer {
    // Overriding to set the text for each tree node.      
    override protected function updateDisplayList(unscaledWidth:Number, 
                                                  unscaledHeight:Number):void {

        super.updateDisplayList(unscaledWidth, unscaledHeight);

        if (super.data) {
            trace("Rendering node:");

            if (super.data is MyClassA) { 
                trace("             MyClassA");
                super.label.text =  MyClassA(super.data).name

            if (super.data is MyClassB) { 
                trace("             MyClassB");
                super.label.text = MyClassB(super.data).id;

    public function NavigateTreeItemRenderer() {


Examining the trace shows I am rendering the node, but I never end up inside either of the two if statements. When I run in the debugger, I can actually the properties on the "data" that correspond to MyClassA and MyClassB!

share|improve this question
add comment

2 Answers

  1. According your conditions you could use another way:

    override public function set data(value : Object) { super.data = value; label.text = ... }

  2. But much simple is write labelFunction

share|improve this answer
The typecheck fails in that method too. They have all the right properties, but cannot be cast to the correct type. I am beginning to wonder if these objects are actually of the correct type coming back from the remote method on the server... –  HDave Oct 9 '11 at 14:56
add comment
up vote 0 down vote accepted

Turns out I was bitten by a subtle issue whereby the ActionScript3 compiler automatically dropped my classes from my remote services SWC because it did not detect any direct reference to those classes. Because those objects are instantiated by RemoteObject result handlers and placed into an child ArrayCollection, there was no reference to them that the compiler could detect.

When this happens, rather than throwing an exception, Flex's RemoteObject implementation simply (and quietly) hydrates them into a generic Object, thus negating the value of their strongly typed interface.

The workaround was to declare a variable within each derived service class for every type of value object that could ever appear within the their object graphs.

share|improve this answer
add comment

Your Answer


