# Frustrated at MVC and HTTPService!

**URL:** https://forum.kirupa.com/t/frustrated-at-mvc-and-httpservice/268746
**Category:** flash
**Created:** [August 18, 2008, 12:21pm UTC](https://forum.kirupa.com/t/frustrated-at-mvc-and-httpservice/268746 "2008-08-18T12:21:27Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Kenwio](https://avatars.discourse-cdn.com/v4/letter/k/eada6e/32.png) [@Kenwio](https://forum.kirupa.com/u/Kenwio)
#### Post date: [August 18, 2008, 12:21pm UTC](https://forum.kirupa.com/t/frustrated-at-mvc-and-httpservice/268746/1 "2008-08-18T12:21:27Z")

</div>

Hi!

I’m trying to redesign a project I’ve been developing to fit a MVH architecture

I’m having trobule with the Model which consits of a class that contains a HTTPService object.

This is the MODEL:

```auto
package classes.model {
    import mx.rpc.events.ResultEvent;
    import mx.rpc.http.HTTPService;
    import XMLList;
    import mx.collections.XMLListCollection;
    import flash.system.Security;
   
    [Bindable]
    public class Stations {
        
        private var _httpService:HTTPService = new HTTPService();
        private var _xmlData:XMLList = new XMLList();
        private var _xmlDataColllection:XMLListCollection;

        public function Stations():void {
            getData();
        }
        
        public function getData():XMLListCollection {
            //This is needed for the Flash Player to grant access to load the PHP data
            Security.loadPolicyFile("http://localhost/crossdomain.xml");
            _httpService = new HTTPService();
            _httpService.url = "http://localhost/phpFile.php";
            _httpService.useProxy = false;
            _httpService.method = "POST";
            _httpService.resultFormat = "e4x";
            _httpService.addEventListener(ResultEvent.RESULT, onResult)
            _httpService.send();
            function onResult(event:ResultEvent):XMLListCollection {
               _xmlData = event.result.fields.field;
               _xmlDataColllection = new XMLListCollection(_xmlData);
               return _xmlDataColllection;
            }
            return _xmlDataColllection;
        }
    }
}

```

This is the VIEW:

```auto
<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" initialize="init()"> 
    <mx:Script>
        <![CDATA[
            import classes.model.Stations;
            import mx.collections.XMLListCollection;
            
            [Bindable]
            private var stationData:Stations;
           
            private function init():void {
                trace (stationData.getData);
            }

        ]]>
    </mx:Script>
    <mx:VBox>
        <mx:DataGrid id="stationGrid" />
    </mx:VBox>
</mx:Panel>

```

When I run this, I get the following error:

```auto
Error #1009: Cannot access a property or method of a null object reference.

```

Please help me!
