0

I have a question about HTTPService and the data it returns.

Well lets consider this XML:

<PhotoGalleryData>
    <Photo>
        <id>1</id>
        <name>Summer Vacation</name>
        <description>In vacation</description>
        <fullImage>originalImg/1.JPG</fullImage>
    </Photo>
    <Photo>
        <id>2</id>
        <name>Winter Vacation</name>
        <description>coold</description>
        <fullImage>originalImg/2.JPG</fullImage>
    </Photo>
</PhotoGalleryData>

As you see i have two instances of Photo, that would be retrieved using a HTTPService, well then on the Result Event of that same HTTPService i would want him the count the amount of instances named Photo he as returned on is .lastResult.

This is a dumb question, but i can't find it anywhere in Adobe Docs.

Of course any help, hint, suggestion is greatly appreciated.


Medoix

I gotta be blind or something, because it still returns 0.

Something missing here?

MXML

<mx:HTTPService id="getData"
    url="{XMLDataFileLocation}"
    showBusyCursor="true"
    fault="getDataFaultHandler()"
    result="getDataResultHandler(event)"/>

ActionScript

import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
private var xmlData:XMLList;
private var numItems:int;
private function getDataResultHandler(evt:ResultEvent):void
{
    if (evt.result.PhotoGalleryData)
    {
        xmlData = XML(evt.result).descendants("Photo");
        numItems = xmlData.length();
        Alert.show('Nº '+numItems,'num de Photo');
    }
}
Amarghosh
  • 58,710
  • 11
  • 92
  • 121
Fábio Antunes
  • 16,984
  • 18
  • 75
  • 96

2 Answers2

2

in the http_result function you have you will be putting this data in an XMLList for an example and then you can call the xmllist.length();

private var xmlData:XMLList;
private var numItems:Integer;

private function HttpResult(evt:ResultEvent):void {
    if (evt.result.PhotoGalleryData) {
        xmlData = XML(evt.result).descendants("Photo");
        numItems = xmlData.length();
    }
}

EDIT: Do the below...

Change

<mx:HTTPService id="getData"
    url="{XMLDataFileLocation}"
    showBusyCursor="true"
    fault="getDataFaultHandler()"
    result="getDataResultHandler(event)"/>

To...

<mx:HTTPService id="getData"
    url="{XMLDataFileLocation}"
    resultFormat="e4x";
    showBusyCursor="true"
    fault="getDataFaultHandler()"
    result="getDataResultHandler(event)"/>

This is working for me.

medoix
  • 1,189
  • 2
  • 16
  • 36
0

Just do the following. it will solve your probs ;)

private var xmlData:XMLList;
private var numItems:Integer;

private function HttpResult(evt:ResultEvent):void {
    if (evt.result.PhotoGalleryData) {

        numItems = ArrayCollection(evt.result.PhotoGalleryData.Photo).length;

    }
}

RSTanvir

RSTanvir
  • 234
  • 2
  • 5
  • Flex doesn't report any error, but Flash does: Error #1034: Type Coercion failed: cannot convert XMLList@2107551 to mx.collections.ArrayCollection. – Fábio Antunes Nov 13 '09 at 17:04