Flex Call ItemRenderer inside a new panel()

1k views Asked by At

I have the below function creating new panels inside my ViewStack.. This works fine and they are great.. However i am trying to put some content into the panels but i am failing.

       private function viewstack_addChild(name:String):void {
            //if (accordion.numChildren < MAX_CHILDREN) {
                var p:Panel = new Panel();
                p.id = name;
                p.name = name;
                p.title = name;
                p.percentWidth = 100;
                p.percentHeight = 100;
                var display:PageItemRenderer = new PageItemRenderer;
                p.finishPrint(display);
                var randColor:uint = Math.random() * 0xFFFFFF;
                p.setStyle("backgroundColor", randColor);
                myViewStack.addChild(p);
                //myViewStack.selectedChild = p;
            //}
        }

I have a custom itemrenderer called PageItemRenderer that will accept the xml data and display it but i cannot figure out how to call the renderer for each panel..

Any help would be greatly appreciated.

EDIT: Adding PageItemRenderer.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:HBox 
height="100%" 
width="100%" 
xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:HBox width="100%" height="100%">
    <mx:VBox height="100%" width="20%" horizontalAlign="center" verticalAlign="middle">
        <!-- software image -->
        <mx:Image source="{data.image}"  width="90%" height="90%"/>
    </mx:VBox>

    <!-- person's name -->
    <mx:VBox height="100%" width="80%" horizontalAlign="left" verticalAlign="middle">
        <mx:Label width="100%" height="100%" text="{data.name} {data.version}" color="#FFAE00"/>
        <mx:Label width="100%" height="100%" text="{data.description}" color="#FFFFFF"/>
    </mx:VBox> 
</mx:HBox>

</mx:HBox>
1

There are 1 answers

10
Ryan Lynch On BEST ANSWER

The Panel is just a container class, and your PageItemRenderer must extend some UIComponent, so just do this in your viewstack_addChild method:

 var p:Panel = new Panel();
 // set the properties on p
 var pR:PageItemRenderer = new PageItemRenderer();
 var data:Object;
 // Do something to get the data to be displayed;
 pR.data = data;
 p.addChild(pR);
 myViewStack.addChild(p);

EDIT: changed pR.setData to pR.data EDIT: changed pR.data(data) to pR.data = data;