views:

116

answers:

2

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 im 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...

A: 

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

sharvey
PageListRenderer is the mxml renderer page. The current code displays the renderer into the panel(); and works if i point the data providers to {Application.application.HomePage.myDG.seletecteditme.name} however this only works when clicking and item in the datagrid and spits out errors when loading and trying to add these items when nothing in the datagrid is selected. Hence why i am trying to put the httpservice data into it... or am i missing something all together lol, thanks for the quick response.
medoix
I have added something i have tried above... still not working tho..
medoix
A: 

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.

AndrewB
Thank you AndrewB!
medoix