Question

I have a httpservice that returns xml data.

<mx:HTTPService id="httpService" url="data/Software.xml" resultFormat="e4x" result="httpResult_handler(event)" fault="Alert.show('XML Data Error')" />

I also have a datagrid using the returned data and also passing it to the renderer which works perfect.

<mx:DataGrid id="myDG" 
dataProvider="{httpService.lastResult.item}"
headerHeight="0"
editable="false"
width="100%" height="100%" 
rowHeight="50"
itemClick="switchView(myDG.selectedItem.name);">

<mx:columns>
<mx:DataGridColumn itemRenderer="com.xd.components.renderers.SoftwareListRenderer" />
</mx:columns>

</mx:DataGrid>

For each result in the xml data I have some code that creates a new panel() and renderer.

private function viewstack_addChild(name:String):void {
            var p:Panel = new Panel();
            p.id = name;
            p.name = name;
            p.title = name;
            p.percentWidth = 100;
            p.percentHeight = 100;
            var randColor:uint = Math.random() * 0xFFFFFF;
            p.setStyle("backgroundColor", randColor);
            var pR:PageListRenderer = new PageListRenderer();
            var data:Object;
            //Do something to get the data to be displayed;
            pR.data = PageListRenderer;
            p.addChild(pR);
            myViewStack.addChild(p);
        }

However I'm not able to use the same {data.name} in this renderer as I do in the datagrid renderer. Instead I get "undefined" for each field... How would I go about passing the {httpService.lastResult.item} to the page renderer also?

EDIT: Changes made..

This is the httpservice result handler.

        private function httpResult_handler(evt:ResultEvent):void {
            if (evt.result.software.item) {

                 data = XML(evt.result).descendants("item");
                    var item:Object = data;
                    for each(item in data) {
                        viewstack_addChild(item.name);
                    }
            }
         }

I have also tried..

        private function httpResult_handler(evt:ResultEvent):void {
            if (evt.result.software.item) {

                 data = httpService.lastResult.item;
                     var item:Object = data;
                     for each(item in data) {
                        viewstack_addChild(item.name);
                    }
            }
         }

I also changed the pR.data = data in the viewstack_addChild function. I am getting the information in the datagrid still, and I am getting the data on each page rendered however each page has the same information (the first result) instead of each result for each page...

Was it helpful?

Solution

I would recommend not making the dataProvider being the data returned from the http service rather bind a variable to be used to store this data. Then any UI component weather initialized or not can use it.

[Bindable]
var httpDataService:Object;

function getData():void 
{
   hpptDataService = httpService.lastResult.item;

. }

datagrid...

dataprovider = "{httpDataService}"

other UI components

dataProvider = httpDataService

or in your case

 data = httpDataService

remember Flex has the cotrols as lazy initialization so if your other control is not initialized at the point where you make your http request it is out of luck. The following is from the view stack reference but pretty much applies to any control that is not visible to the user until selected...

Note: The default creation policy for all containers, except the Application container, is the policy of the parent container. The default policy for the Application container is auto. In most cases, therefore, the View Stack control's children are not created until they are selected. You cannot set the selectedChild property to a child that is not yet created.

OTHER TIPS

I think the problem is that you set data to be PageListRenderer, which look suspiciously like a class instead of the data you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top