1 Reply Latest reply on Jul 23, 2010 2:07 AM by BhaskerChari

    Problem while adding elements to a ArrayCollection

    kiran7881 Level 1

      Hi ,

      I am trying to insert some Strings in ArrayCollection using addItem("Test")

      but it is throwing compile error showing that "the variable Test1 is not defined"

       

      Problem in adding elemnets to a

      Some sample code

      <mx:Application creationComplete="callMe()">
      <mx:script>
      public function callMe():void
      {

      var ac:ArrayCollection = new ArrayCollection();
      ac.addItem("Test1");
      ac.addItem("Test2");
      ac.addItem("Test3");
      }
      </mx:script>

      </mx:Application>

      Please let me know how can i solve this error .

      Thanks in advnace .

      I also tried using

      var str:String ="Test1";


      ac.addItem(str);

      but the problem continous

      Please help .

        • 1. Re: Problem while adding elements to a ArrayCollection
          BhaskerChari Level 4

          Hi Kiran,

           

          Try the below code as it is pasted below:

           

          I think you have used ac.addItem(Test1);  instead of ac.addItem("Test1"); ..thats why it is throwing an error...

           

          <?xml version="1.0"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="callMe()">
          <mx:Script>
            <![CDATA[
             import mx.collections.ArrayCollection;
             public function callMe():void
             {
              var ac:ArrayCollection = new ArrayCollection();
              ac.addItem("Test1");
              ac.addItem("Test2");
              ac.addItem("Test3");
             }
            ]]>
          </mx:Script>

          </mx:Application>

           

           

           

          Thanks,

          Bhasker Chari