3 Replies Latest reply on Sep 25, 2006 6:10 AM by Ed_Syrett

    Array Invocation not recognised

    Mr Binitie
      I have declared an array as a class property. However when I seek for the array length property, I an told by FlexBuilder2 (Access of undefined property length in package listeners). Here is a snippet of the code

      package events{

      import events.*;
      import listeners.*;
      import flash.display.Sprite;
      import flash.net.URLRequest;
      import flash.events.Event;

      public class EventListenerList extends Sprite
      private var listeners:Array;

      public function EventListenerList ()
      var listeners = new Array();

      public function addObj (l:IEventListener):Boolean
      var len:Number = listeners.length;
      for (var i:Number = len; --i >= 0;)
      switch (listeners )
      case l:
      return false;

      trace ("New Listener added::")
      return true;

      // Just a cutaway of the code
      // More code here so neither the package
      // nor class is closed in this snippet

        • 1. Re: Array Invocation not recognised
          inlineblue Level 1
          In your EventListenerList constructor, remove the "var". What you did was declare a local variable called "listeners" and initialized that. The listeners property never got initialized.
          • 2. Re: Array Invocation not recognised
            Mr Binitie Level 1
            Thank you for the response.
            Placing the var there was actually an act of desperation. The initial code refered to the class private property listeners. I have removed the var so I now have

            public function EventListenerList ()

            listeners = new Array();


            and yet I still get an error for

            var len:Number = listeners.length

            //Description Access of undefined property length in package listeners. EventListenerList.as

            This error is same for every argument in the class document that has any reference to that array

            Also I find that the code hints only give me options for classes and interfaces within the events package. I cannot get access to the Top Level Classes. I'd appreciate your help here.
            • 3. Re: Array Invocation not recognised
              The first problem is that Flex is getting your class variable listeners very confused with the package listeners. If you rename your class level var to something else, the error message goes away.

              Now I'm intrigued as to what this code is supposed to do...

              What is switch(listeners) supposed to do? If you're comparing it to a number, houldn't that be listeners.length?