girl_coder
girl_coder

Reputation: 25

Loading XML file using HTTPService in Flex

So I have been trying to load data from an XML file into a datagrid. The project is in Cairngorm framework. The XML file is in the web content folder. I have a HTTPService call in the Services folder.

<mx:HTTPService
        id = "getCategory"
        url = "assets/CategoryDept21Class1.xml"
        resultFormat = "e4x"
        />

When I make a selection in one dataGrid it is supposed to populate another dataGrid with the data in the XML file. Below is the Classes datagrid. When i click on a class it is supposed to populate the next data grid.

<mx:DataGrid rowCount="10" enabled="true"
         dataProvider="{classList}"
         verticalScrollPolicy="on"
         click = "onClass()"
         id="classes" width="192" top="73" left="253" height="225">
        <mx:columns>
            <mx:DataGridColumn headerText="#" dataField="merchandiseClassNumber" width="50"/>
            <mx:DataGridColumn headerText="Class Name" dataField="merchandiseClassDescription" width="150"/>
        </mx:columns>
    </mx:DataGrid>

These are the methods that will be triggered.

private function selectClass(evt:ResultEvent):void{
                //this.categoryList = new XMLListCollection(evt.result.resultSet);
                this.categoryList= evt.result.resultSet.MerchandiseAssortmentCategory;
                var request:AMTCategoryEvent;
                CairngormEventDispatcher.getInstance().dispatchEvent(request);

            }

            private function onClass():void{
                //Alert.show("you just clicked on a class ");
                var event:AMTCategoryEvent = new AMTCategoryEvent();
                CairngormEventDispatcher.getInstance().dispatchEvent(event);
            }

this is how i defined getCategory() in my delegate

public function getCategory() : void
        {
            service = ServiceLocator.getInstance().getHTTPService("getCategory") as HTTPService;
            //Alert.show(service.url);
            var token : AsyncToken = service.send();
            token.addResponder(responder);
        }   

and this is what i have in my getCategoryCommand.

public function execute(event: CairngormEvent) : void{
            var categoryEvent: AMTCategoryEvent = event as AMTCategoryEvent;
            var deleg:Delegate = new Delegate(this);
            deleg.getCategory();
            //deleg.getCategory(categoryEvent.deptNumber, categoryEvent.classNum);
        }

        public function result(info:Object) :void{
            trace("Get Category: Success");
        //  __model.categoryList = new XMLList(info.result.resultSet.MerchandiseAssortmentCategory);
            var xmlbleh:XMLList=info.result.resultSet.MerchandiseAssortmentCategory.lastResult;
            mx.controls.Alert.show(xmlbleh.toXMLString());
            __model.categoryList = new XMLListCollection(XMLList(info.result.resultSet.MerchandiseAssortmentCategory.lastResult));

    }

It is not reading the data in the xml file into the datagrid for some reason. This is my first question on this website I don't kno if my question is clear. But how would i do that? Thanks :)

Upvotes: 0

Views: 1796

Answers (1)

billygoat
billygoat

Reputation: 21984

The question is clear enough, but you might have extra information that might be useful. I will try to elucidate those through a series of questions. (This probably belongs to comments, but there is size limits there and it might become cumbersome)

1- I hope that you managed to get the reference of the HttpService in your delegate.

2- I hope that you managed to debug till the point that the async service call is made.

3- I assume that the result call back function is never called. ( or fault for that matter).

4- I assume that the application is deployed in a web server.

If all my assumptions are right, then the problem could be with the formation of url. I assume you are trying to provide a relative path, but I will try to provide absolute url. If the problem is with the url, then the service call should have been logged in your back ground and you should be seeing a error message like 404).

If there are no apparent error messages, then this could be a security error. Did you provide crossdomain policy file.

If any of my assumptions are wrong, please fill in with necessary information. Also please provide the Flex SDK version.

Note: In case if you are running this as a standalone application, then there is a security constraint that will not allow you to read from file system, unless you provide additional attributes in your Flash Builder.

Upvotes: 1

Related Questions