Use E4X to total the prices of all of the elements with a price attribute : At : XML Flash / Flex / ActionScript examples


Flash / Flex / ActionScript examples » XML » At »

 

Use E4X to total the prices of all of the elements with a price attribute


 


package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){

        var cart:XML = <cart>
                          <item price=".98">crayons</item>
                          <item price="3.29">pencils</item>
                          <group>
                            <item price=".48">blue pen</item>
                            <item price=".48">black pen</item>
                          </group>
                        </cart>;
        
        var total:Number = 0;
        
        for each var price:XML in cart..@price ) {
          total += price;    
        }
        
        tracetotal );

    }
  }
}

        



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


Flash / Flex / ActionScript examples

 Navioo XML
» At