1 Reply Latest reply on May 15, 2006 7:22 AM by abeall

    Array.prototype problems

    had3z
      i wrote an array.prototype function which added an unique element, but then all the comboboxes behaved strange. i tracked the problem down to this

      Array.prototype.doesntmatter = function(element) {
      for (var i in element) {
      trace(i + ' ' + element );
      }
      this.push('wuzaa'); // this adds extra lines on combobox component. doesn't work with this[this.length] either
      }
      list1.addItem("?!");

      , and add a combobox named list1. somehow, this function is called whenever i click on the combo, (which add extra items) and afterwards every time i hit a key. outputs things like this

      target _level0.depthChild0
      type reveal

      target _level0.list1
      type keyDown
      code 17
      ascii 0
      shiftKey false
      ctrlKey true

      does somebody know how to fix this, other than creating a function with the array and new element as parameters?
      flash mx 2004, v7.2
        • 1. Re: Array.prototype problems
          abeall Level 3
          It may be related to the fact that objects you add to the prototype object get accessed by the for...in loop, at least by default.
          Try:
          myAr = [1,2,3,4,5,6,7];
          for(var i in myAr){
          trace(i+" = "+myAr )
          }
          And notice it traces all your elements, plus your prototype function.

          If a component is using for...in, which it seems likely it would, this could mess things up.

          However! You can manually "hide" your objects attached to prototype, as well as some other funky things, with the undocumented ASSetPropFlags function.
          http://www.flashguru.co.uk/assetpropflags/

          HTH