12 Replies Latest reply on Aug 14, 2008 8:54 AM by tomez85

    addItemAt error

    whiterrabbit Level 1
      I have a cartArray:arrayCollection

      when I click a button I call the below function which starts looping this error
      warning: unable to bind to property 'qty' on class 'Object' (class is not an IEventDispatcher)
      warning: unable to bind to property 'simagesource' on class 'Object' (class is not an IEventDispatcher)

      Both img and qty have the correct values, why can I not insert this into the array collection. Does it have anything to do with the 1 item bug? Thanks for your help
        • 1. addItemAt error
          whiterrabbit Level 1
          Well, part of the problem was not in this function but I was not actually binding to the right variables. Here is my new code with dynamic index position variable. When I run it, the first object is added. When the second object is added the first object appears to be dropped.

          what am I doing wrong.
          • 2. Re: addItemAt error
            Loquiz755 Level 1
            cartArray.addItemAt(cartObj,addposition);

            I don't see where you increment addposition, you should have addposition++ that way it inserts the item on the next available position if not it will overrite the 0 index position.
            • 3. Re: addItemAt error
              Loquiz755 Level 1
              cartArray.addItemAt(cartObj,addposition);

              I don't see where you increment addposition, you should have addposition++ that way it inserts the item on the next available position if not it will overwrite the 0 index position.
              • 4. Re: addItemAt error
                whiterrabbit Level 1
                In my second post (sample code) the position is set to array length.
                The array is a 0 index so first item is placed at 0
                Then length is 1 so second item is placed at 1
                and so on....
                • 5. Re: addItemAt error
                  Garyl Woolworth Level 1
                  He shouldn't technically need to increment addposition on his own because he is setting it to be the length of the array each time the method is run which every time the method is run he is adding a new item, so that alone increments addposition. whiterrabbit I've written a test example that seems to be working for me using addItemAt I'm not really sure why your code is overwriting without seeing the full thing but maybe you can compare the two and figure out the differences.
                  • 6. Re: addItemAt error
                    whiterrabbit Level 1
                    Kaotic,

                    that stopped me from overwriting, must have been the way I was adding it through the Object tags, just took that from a book.

                    Im still getting a warning error
                    warning: unable to bind to property 'imgqty' on class 'Object' (class is not an IEventDispatcher)
                    warning: unable to bind to property 'imagename' on class 'Object' (class is not an IEventDispatcher)

                    going to look around a bit to see why this would happen. I am binding to a TileList like this -
                    • 7. Re: addItemAt error
                      m_hartnett Level 3
                      Your problem is that you have defined your cartObj at the wrong level.
                      Everytime you add the object to the arraycollection, it is the same object, you are just assigning its properties new values. That is why all of the cart items have the same value.

                      Move your cartObj into the method and then create it. Assign the property values at that point and add it to the arraycollection.


                      private function additem():void {
                      var cartObj:Object= new Object();
                      addposition = cartArray.length;
                      img = simgsource;
                      qty = 1;
                      cartObj.imagename = img;
                      cartObj.imgqty = qty;
                      cartArray.addItemAt(cartObj,addposition);
                      trace(addposition);
                      }
                      • 8. Re: addItemAt error
                        whiterrabbit Level 1
                        Thanks mhartnett, I see it now.

                        any idea on the warnings im getting
                        • 9. Re: addItemAt error
                          m_hartnett Level 3
                          You cannot bind to an Object because it does not implement the IEventDispatcher. You can wrap the object in a ObjectProxy if you would like;
                          • 10. Re: addItemAt error
                            Garyl Woolworth Level 1
                            You can use something called ObjectProxy to get rid of those warnings. Before you add your item into the arrayCollection run it through ObjectProxy similiar to the following.
                            • 11. Re: addItemAt error
                              whiterrabbit Level 1
                              Thanks that did it.
                              just change a to b in the addItemAt()


                              • 12. Re: addItemAt error
                                tomez85 Level 1
                                Thanks so much! ObjectProxy solved my problem! Thanks again!