4 Replies Latest reply on Apr 10, 2009 3:26 PM by 123qweads

    ArrayCollection & AddEventListener: error 1006

    123qweads
      HI..
      in order to handler some custom components (usuallyCanvas) I need to put them in an ArrayCollection....


      the problem is that a this point I can't use AddEventListener on AC objects.....

      myArrayCollection[index].AddEventListener give me the error nr. 1006...
      because AddEventListener is not a method for myArrayCollection[index]
      someone can help me? 

      questa soluzione http://www.gongon2.com/flex/pippo/bin/OrizListOL.html non posso usarla...

      now I show you how make AC, maybe error is here...

      Codice:
      import com.myComponents.*;

      private function LoadInterfaces():void {
           myArrayCollection.addItemAt( FirstMenu, 0 );
           myArrayCollection.addItemAt( SecondMenu, 1 );
           myArrayCollection.addItemAt( ThirdMenu, 2);
      }
      in com.myComponents there are Firs Second e Third menu, of course

      bye and thanks for aids
        • 1. Re: ArrayCollection & AddEventListener: error 1006
          Michael Borbor Level 4

          Hi there, if you want to handle components you should add the event listener to the components, why do you want to add a listener to the AC? Even though you could use setters  to have some sort of awareness over the ac changes.

          • 2. Re: ArrayCollection & AddEventListener: error 1006
            Gregory Lafrance Level 6

            Menu(myArrayCollection[index].AddEventListener(.........));

             

            where Menu is whatever type you are dealing with (need to know in advance).

            1 person found this helpful
            • 3. Re: ArrayCollection & AddEventListener: error 1006
              ergo_eleven

              You problem is that you trying to assign event listener to an object that does not an IEventDispatcher.
              Consider example:

               

              public function init():void
              {
                  var ac : ArrayCollection = new ArrayCollection([1, 2, 3]);
                  ac[1].addEventListener("click",
                      function (event : MouseEvent) : void
                      {
                          trace("on click");
                      });
              }

               

              It fails with error 1006, because 2 (object of Nuber) is not implements intreface IEventDispatcher.
              Run this one:

              public function init():void
              {
                  var b1 : Button = new Button();
                  var b2 : Button = new Button();
                  var b3 : Button = new Button();
                  addChild(b1);
                  addChild(b2);
                  addChild(b3);
              
                  var ac : ArrayCollection = new ArrayCollection([b1, b2, b3]);
                  ac[1].addEventListener("click",
                      function (event : MouseEvent) : void
                      {
                          trace("on click");
                      });
              }
              

               

              In debug mode when you'll press on second button will see "on click" message in console.
              So everything is ok.

               

              Good luck!

              1 person found this helpful
              • 4. Re: ArrayCollection & AddEventListener: error 1006
                123qweads Level 1

                @Michael Borbor

                Hi there, if you want to handle components you should add the event listener to the components, why do you want to add a listener to the AC? Even though you could use setters  to have some sort of awareness over the ac changes.

                 

                Because, I must add and remove differents effect listener... so I want handle my menu  only a structure, myArrayCollection

                 

                 

                @Greg Lafrance

                Menu(myArrayCollection[index].AddEventListener(.........));

                where Menu is whatever type you are dealing with (need to know in advance).

                 

                Thank but doesn't work.... I've tried with DisplayObject but cast give me an error...

                cast in Object works, but Object has not AddEventListener

                 

                 

                @ergo_eleven

                You problem is that you trying to assign event listener to an object that does not an IEventDispatcher. [omissis]

                 

                Yes, you have hit the target,

                but I prefered don't create a new istance.....

                 

                but if this is the only way, I'll walk it...

                 

                 

                Thanks at all three for your advice!