3 Replies Latest reply on Sep 6, 2007 8:22 AM by Handycam

    Checking if items exist without RTEs

    Handycam Level 1
      I have an app with 2 datagrids, designed for drag and drop.

      The "drag from" one has a dataprovider of an XMLList.

      For the "drag to" one, I have an ArrayCollection called _chosen0:

      [Bindable] public var _chosen0:ArrayCollection = new ArrayCollection();

      It seems to work great. However, I later need to access members of the second grid (_chosen0) and do stuff.

      If there are item(s) in _chosen0, no problem. I can do "trace(app._chosen0[0].@ln1)".

      My problem is if there are no choices yet, trying something like the above trace statement causes a RTE. How can I check for the presence of the item(s) before trying to access the data? I tried this:

      private function checkItems():void {
      if (app._chosen0 != null){
      trace(app._chosen0[0].@ln1); }

      But I get a RTE:
      RangeError: Index '0' specified is out of bounds.
      at mx.collections::ListCollectionView/getItemAt()
      at mx.collections::ListCollectionView/ http://www.adobe.com/2006/actionscript/flash/proxy::getProperty()