Your answer involves looping externally (which is how they explain it in the flex code sample). I was trying to avoid that and use e4x's power to do the same. Therefore I was calling a function within the e4x expression. I know that calling a function within e4x expression works because I am doing other conversions on attributes. I thought the summing up of attributes should work too.
Anyways, thanks for the quick response. --- In [email protected], "Matt Horn" <[EMAIL PROTECTED]> wrote: > > Here's a basic example using for each: > > <?xml version="1.0"?> > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> > <mx:Script><![CDATA[ > > private var myXML:XML = > <order> > <item id='1' quantity='2'> > <menuName>burger</menuName> > <price>3.95</price> > </item> > <item id='2' quantity='1'> > <menuName>fries</menuName> > <price>1.45</price> > </item> > </order> > > private function sumTotal():void { > var t:Number = 0; > > for each (var property:XML in myXML.item) { > var q:int = [EMAIL PROTECTED]; > var p:Number = property.price; > var total:Number = q * p; > t += total; > } > > l1.text = "$" + t.toString(); > } > > ]]></mx:Script> > <mx:Label id="l1"/> > <mx:Button id="b1" click="sumTotal()" label="Get Total"/> > </mx:Application> > > hth, > > matt horn > flex docs > > > -----Original Message----- > > From: [email protected] > > [mailto:[EMAIL PROTECTED] On Behalf Of coder_flex > > Sent: Thursday, June 22, 2006 10:49 PM > > To: [email protected] > > Subject: [flexcoders] e4x adding attributes across members. > > > > If my xml structure looks like this: > > > > var inputXML:XML = > > <books> > > <book name="da vinci code" author="dan brown" price="12.22" > > quantity="2"/> > > <book name="angels and daemons" author="dan brown" price="10.20" > > quantity="4"/> > > <book name="digital fortress" author="dan brown" price="12.22" > > quantity="5"/> > > </books>; > > > > I wanted an e4x expression to get the total of price*quantity > > across all the books. > > > > The way I am trying to achieve this is: > > define a function: > > public function addToTotal(totalObj:Object, > > perBookTotal:Number):void { totalObj.totalAmt+=perBookTotal; } > > > > then call the function from e4x expression: > > > > var totalClass = new Object(); > > totalClass.totalAmt = 0; > > > > inputXML.book.(addToTotal( > > totalClass, Number(@price)*Number(@quantity))); > > trace(totalClass.totalAmt); > > > > I am in the process of trying this. Is this going to work at > > all? Or is there a better way of achieving this. > > > > Thanks in advance for all the help. > > > > > > > > > > > ------------------------ Yahoo! Groups Sponsor --------------------~--> Yahoo! Groups gets a make over. See the new email design. http://us.click.yahoo.com/XISQkA/lOaOAA/yQLSAA/nhFolB/TM --------------------------------------------------------------------~-> -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/

