2 Replies Latest reply on Feb 29, 2008 8:42 AM by Handycam

    Function works, but breaks used in Class

    Handycam Level 1
      I have this function I use over and over in my applications (Addins is but one item I have to do this to):

      private function doAddins():void {
      var _addIns:Array = [];
      var _len:uint = app._chosen2.length;
      for (var i:int=0; i<_len; i++) {
      var _m:String = app._chosen2 .@sn;
      _addIns.push(_m);
      }
      }

      Where "_chosen2" is an ArrayCollection defined in the main application file. Obviously, it loops through this array collection and makes an array out of all the "sn" attributes. It works perfectly.

      So I figured I'd add it to my Utilities class file, as a static function, like:

      public static function getSNs(a:ArrayCollection):Array {
      var _arr:Array;
      var _len:uint = a.length;
      for (var i:int=0; i<_len; i++) {
      var _m:String = a.@sn;
      _arr.push(_m);
      return _arr;
      }

      And then I call it like : Utitlies.getSNs(app._chosen2);

      But it bombs out with an error that I am trying to coerce an array out of an array collection. Why?