Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have published a network analyst service and I'm trying to use it from the Flex API 3.1. When I use the service in ArcMap or through the rest GUI in a browser, the service returns the right answer. When I use the service from the Flex API 3.1, my object "routeResult" that contains the route returned by the server is null. I get the error: "Error #1009: Cannot access a property or method of a null object reference." for the object routeResult. Here is my application code:

<s:layout>
    <s:BasicLayout/>
</s:layout>

<fx:Script>
    <![CDATA[
        import com.esri.ags.events.MapMouseEvent;
        import com.esri.ags.events.RouteEvent;
        import com.esri.ags.FeatureSet;
        import com.esri.ags.Graphic;
        import com.esri.ags.symbols.CompositeSymbol;
        import com.esri.ags.symbols.SimpleMarkerSymbol;
        import com.esri.ags.symbols.TextSymbol;
        import com.esri.ags.tasks.supportClasses.RouteResult;

        import mx.controls.Alert;
        import mx.rpc.events.FaultEvent;

        [Bindable]private var stops:FeatureSet = new FeatureSet([]);

        [Bindable]private var lastRoute:Graphic;            

        private function mapClickHandler(event:MapMouseEvent):void
        {
            var stopSymbol:CompositeSymbol = new CompositeSymbol();
            var circleSym:SimpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, 20, 0x000099);
            var textSym:TextSymbol = new TextSymbol(String(stops.features.length + 1));
            textSym.textFormat = new TextFormat("Verdana", null, null, true);
            textSym.color = 0xFFFFFF;
            stopSymbol.symbols = [ circleSym, textSym ];

                            var stop:Graphic = new Graphic(event.mapPoint, stopSymbol);
            inputsLayer.add(stop);
            stops.features.push(stop);

            if (stops.features.length > 1)
            {
                routeTask.solve(routeParams);
            }
        }

        private function solveCompleteHandler(event:RouteEvent):void
        {
            var routeResult:RouteResult = event.routeSolveResult.routeResults[0];
            lastRoute = routeResult.route;
            lastRoute.toolTip = routeResult.routeName;
            if (routeResult.route.attributes.Total_Time)
            {
                lastRoute.toolTip += " in " + Math.round(Number(routeResult.route.attributes.Total_Time)) + " minutes.";
            }
        }

        private function faultHandler(event:FaultEvent):void
        {
            Alert.show(event.fault.faultString + "\n\n" + event.fault.faultDetail, "Routing Error " + event.fault.faultCode);
            // Supprimer le dernier stop ou les deux s'il n'y en a pas plus.
            if (stops.features.length <= 2)
            {
                inputsLayer.clear();
                stops = new FeatureSet([]);
            }
            else
            {
                inputsLayer.remove(stops.features.pop());
            }
        }

    ]]>
</fx:Script>    

<fx:Declarations>       
    <esri:MapPoint id="mapPoint" x="655672" y="6861079"/>

    <esri:RouteTask id="routeTask" concurrency="last" fault="faultHandler(event)"
                    requestTimeout="30" showBusyCursor="true"
                    solveComplete="solveCompleteHandler(event)"
                    url="http://serverIP:8399/arcgis/rest/services/na_service/MapServer/Route"/>

    <esri:RouteParameters id="routeParams" stops="{stops}" returnDirections="false"/>

    <esri:SimpleLineSymbol id="routeSymbol" width="5" alpha="0.6" color="0x000099"/>
</fx:Declarations>

<s:BorderContainer id="applicationHolder" width="100%" height="100%">


    <s:layout>
        <s:VerticalLayout/>
    </s:layout>

    <s:SkinnableContainer id="headerBar" width="100%" height="50" backgroundColor="0xcccccc">
        <s:layout>
            <s:HorizontalLayout verticalAlign="middle"/>
        </s:layout>

        <mx:Text id="titleText" fontSize="25" fontWeight="bold"
                 text="My application"/>
        <mx:Spacer width="75"/>         

    </s:SkinnableContainer>

    <esri:Map id="mainMap" width="100%" height="100%" center="{mapPoint}"
              crosshairVisible="{crosshairsCheck.selected}" level="16"
              mapClick="mapClickHandler(event)" panArrowsVisible="{panArrowsCheck.selected}">
        <esri:ArcGISDynamicMapServiceLayer url="http://serverIP:8399/arcgis/rest/services/myMapService/MapServer"/>

        <esri:GraphicsLayer graphicProvider="{lastRoute}" symbol="{routeSymbol}"/>
        <esri:GraphicsLayer id="inputsLayer"/>
    </esri:Map>

</s:BorderContainer>

Do you have any advice?

Regards

share|improve this question
    
Have you used firebug or fiddler to make sure all the parameters being passed in are correct? –  Jamie Dec 27 '12 at 16:16
    
@Jamie In FireBug parameters are : f json returnBarriers false returnDirections false returnPolygonBarriers false returnPolylineBarriers false returnRoutes true returnStops false stops {"features":[{"geometry":{"x":655563.9391567005,"spatialReference":{"wkid"‌​:2154},"y":6861469.492592832}},{"geometry":{"x":655344.5428990924,"spatialReferen‌​ce":{"wkid":2154},"y":6861367.980891551}}],"doNotLocateOnRestrictedElements":fals‌​e,"type":"features"} So I suppose yes. The parameters sent to the server are correct. –  yo_haha Dec 27 '12 at 16:46

1 Answer 1

up vote 1 down vote accepted

Solved. In the object Routetask:

<esri:RouteTask id="routeTask" concurrency="last" fault="faultHandler(event)"
                    requestTimeout="30" showBusyCursor="true"
                    solveComplete="solveCompleteHandler(event)"
                    url="http://serverIP:8399/arcgis/rest/services/na_service/MapServer/Route"/>

In the url attribute, there is a mistake. Instead of /MapServer there should be /NAServer like this:

url="http://serverIP:8399/arcgis/rest/services/na_service/NAServer/Route"
share|improve this answer
    
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. –  R.K. Dec 28 '12 at 14:50
    
Ok thanks for the comment. I'm the author of the question and I have answered it. I have provided a more detailed answer. I agree with you, the previous answer wasn't clear. –  yo_haha Dec 28 '12 at 15:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.