First, on the operation, set resultFormat="e4x". The default "object"
has many drawbacks, search the archives for details.
Then modify your handler to work with XMLListCollection
[Bindable]public var storyFeed:XMLListCollection;
public function buildBookHandler(e:ResultEvent):void {
var xmlResult:XML = XML(e.result);
trace(xmlResult.toXMLString()); //to see your xml structure
var xlStoryFeed:XMLList = xmlResult.What.Ever.Path.To.Story.nodes;
//depends on xml structure
trace(xlStoryFeed.toXMLString()); //this what you expect
storyFeed = new XMLListCollection(xlStoryFeed); //now you can use
this for a dataProvider
//If youwant to loop over the data, use the XMLList
var xmlStoryNode:XML
for (var i:uint = 0; i < xlStoryFeed.length(); i++){ //note the
parens on length
xmlStoryNode = xlStoryFeed[i];
...
storyArea.text = xmlStoryNode.story; //assumes <story> child node
...
Tracy Spratt
Lariat Services
Flex development bandwidth available
________________________________
From: [email protected] [mailto:[email protected]] On
Behalf Of Wally Kolcz
Sent: Wednesday, January 21, 2009 12:40 PM
To: [email protected]
Subject: [flexcoders] What is the results of a web service
I am having fits trying to figure out how to use the information coming
back from a webservice. I created a web service call in my code:
<mx:WebService id="storyGateway"
wsdl="http://www2.med.umich.edu/prmc/media/newsroom/stories.cfc?wsdl"
fault="Alert.show(event.fault.message,'Story Gateway Error')">
<mx:operation name="listBySubject"
result="buildBookHandler(event)"
fault="Alert.show(event.fault.message,'Story Gateway Error')" />
</mx:WebService>
It returns the data as requested, I can see it in my debugging, but I
cannot figure out how to set it to a variable and then call the various
elemenets (linkText, story, photo, defaultLogo)
I tried to set it to a variable as an ArrayCollection:
[Bindable]
public var storyFeed:ArrayCollection = new
ArrayCollection();
public function buildBookHandler(e:ResultEvent):void {
storyFeed = e.result as ArrayCollection;
for (var i:uint = 0; i < e.result.data.length; i++){
...
//Story Area
var storyArea:TextArea = new TextArea();
storyArea.text = storyFeed.getItemAt(i).story;
storyArea.wordWrap = true;
storyArea.height = 550;
storyArea.width = 400;
storyArea.editable = false;
magPage.addChild(storyArea);
storyArea.x = 0;
storyArea.y = 25;
...
}
rssMag.flipOnClick = true;
}
But still getting errors..
TypeError: Error #1009: Cannot access a property or method of a null
object reference.
at RSSMagazine/buildBookHandler()[D:\wkolcz\My Documents\Flex
Builder 3\RSSMagazine\src\RSSMagazine.mxml:36]
Line 36 is:
storyArea.text = storyFeed.getItemAt(i).story;
Help!