How can I force a tree itemrenderer to redraw during a drag and drop operation?

Posted by swidnikk on Stack Overflow See other posts from Stack Overflow or by swidnikk
Published on 2010-06-11T21:14:01Z Indexed on 2010/06/12 6:22 UTC
Read the original article Hit count: 734

Filed under:
|
|
|
|

I have a tree control with a custom item renderer. The item renderer has different states that should be set while an item is being dragged over the item renderer. I understand from reading this post http://forums.adobe.com/message/2091088 that the 'right way' to do this is to override the 'getCurrentState' method and append some text. I do that.

Now in my tree control I handle the drag over event and get a reference to the itemrenderer that is being dragged over and I set the boolean 'dragOver' property to true. Now I just need to force my itemRenderer to redraw. I can't figure that out. A workaround, is to just set the currentState of the itemRenderer.

My question then, how can I force my itemRenderer to refresh? (and I've tried calling validateNow, invalideDisplayList/Properties/Size, to no avail)

<?xml version="1.0" encoding="utf-8"?>
<s:MXTreeItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx">

    <fx:Script>
        <![CDATA[           
            import mx.events.DragEvent;
            import mx.events.FlexEvent;

            import spark.layouts.supportClasses.DropLocation;

            public var dragOver:Boolean = false;

            override protected function getCurrentRendererState():String
            {

                var skinState:String = super.getCurrentRendererState();

                if( dragOver )
                    skinState += "AndDragOver";

                trace('getCurrentRendererState', skinState);
                return skinState;
            }

        ]]>
    </fx:Script>

    <s:states>
        <s:State name="normal" />            
        <s:State name="hovered" />
        <s:State name="selected" />
        <s:State name="normalAndDragOver" stateGroups="dragOverGroup" />            
        <s:State name="hoveredAndDragOver" stateGroups="dragOverGroup" />
        <s:State name="selectedAndDragOver" stateGroups="dragOverGroup" />
    </s:states>

...

© Stack Overflow or respective owner

Related posts about flex

Related posts about drag-and-drop