1 Reply Latest reply on Jun 24, 2011 10:43 AM by GordonSmith

    Error #1010 on dynamic array of Labels?

    kid electric Level 1

      I am attempting to create an array of words as dynamically-created Labels that act like buttons (ie. they are plain text but are clickable and will highlight on mouseover).  This method works (using names like "word1", "word2"..."wordN" as the array index) for inserting the word labels into a BorderContainer... so the array seems to be okay. However, when I go to mouseover, I get TypeError: Error #1010: A term is undefined and has no properties.

       

      Pretty cryptic. What term is undefined and has no properties? I was assuming I could self-reference the event-triggering element using "this"... is that the problem? Not sure why the label can be added as a child element okay, but when I try to access one of the labels in the array, it gives "term undefined and has no properties"...

       

              private function mouseoverWord(event:Event):void {
                  // Event handler for what happens when a mouse is moved over a word
                  clickableArray[this.id].setStyle("color", "blue");
              }
                 
              private function mouseclickWord(event:Event):void {
              // Event handler for when word is clicked   
              }
         
              private function createTextWord(word:String, num:int):void {
                  var wordLabel:spark.components.Label = new spark.components.Label;
                  wordLabel.text = word;
                  wordLabel.buttonMode = true;
                  wordLabel.addEventListener(MouseEvent.MOUSE_OVER, mouseoverWord);
                  wordLabel.addEventListener(MouseEvent.CLICK, mouseclickWord);
                  wordLabel.id = "word"+num.toString();
                  clickableArray[wordLabel.id] = wordLabel;
              }

        • 1. Re: Error #1010 on dynamic array of Labels?
          GordonSmith Level 4

          > I was assuming I could self-reference the event-triggering element using "this"... is that the problem?


          Possibly. If this code is in MyApp.mxml (and not within a <Component> or  <Definition>, then 'this' is a reference to the instance of MyApp. The object which dispatched the event is event.target.

           

          Gordon Smith

          Adobe Flex SDK Team