4 Replies Latest reply on Jul 16, 2007 6:15 AM by jnguye19

    List Control addItem

    PowerHorse
      Hi,
      I've been trying the sample My First Flex in Flex 2 Builder.
      I'm doing fine until this line...
      cart.addItem(coffeeCombo.selecteItem.label,coffeeCombo.selectedItem.data);
      this line is giving me error.
      Actually I followed all the code given in sample and it's working fine until the above line which
      was not working.

      Thanks
        • 1. Re: List Control addItem
          jnguye19
          I also am having trouble with that tutorial. After I changed Void to void, I get this error:

          1061: Call to a possibly undefined method addItem through a reference with static type mx.controls:List.

          at:

          cart.addItem(coffeeCombo.selectedItem.label,coffeeCombo.selectedItem.data);

          This is in reference to the adobe tutorial found at

          http://www.adobe.com/devnet/flex/articles/first_flexapp_13.html

          Any help?
          • 2. Re: List Control addItem
            kcell Level 2
            try these code:

            <?xml version="1.0"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" >
            <!-- data model -->
            <mx:Array id="coffeeArray">
            <mx:Object label="Red Sea" data="Smooth and fragrant"/>
            <mx:Object label="Andes" data="Rich and pungentt"/>
            <mx:Object label="Blue Mountain" data="Delicate and refined"/>
            </mx:Array>
            <mx:ArrayCollection id="listArray"/>
            <mx:Script>
            <![CDATA[
            public function addToCart():void
            {
            var aObject:Object = new Object();
            aObject.label = coffeeCombo.selectedItem.label;
            aObject.data = coffeeCombo.selectedItem.data;

            listArray.addItem(aObject);
            }
            ]]>
            </mx:Script>
            <!-- view -->
            <mx:Panel title="My First Flex App">
            <mx:Label text="Coffee Blends"/>
            <mx:ComboBox id="coffeeCombo" dataProvider="{coffeeArray}"/>
            <mx:Text text="{coffeeCombo.selectedItem.data}"/>
            <mx:Button label="Add to Cart" click="addToCart()"/>
            <mx:List id="cart" dataProvider="{listArray}"/>
            </mx:Panel>
            </mx:Application>
            • 3. List Control addItem
              Had the same problem... Struggled a little with it before ending up here.

              Is it a version problem?
              • 4. Re: List Control addItem
                jnguye19 Level 1
                I found in another post that this tutorial is for version 1.5, which is a bit different from version 2.0

                Adobe needs to update their tutorials or at least bring out the fact that the tutorial is only for version 1.5