0 Replies Latest reply on Feb 12, 2007 10:02 PM by AniMaison

    onRelease, loops, level10 v level10.button ???

    AniMaison Level 1
      After looking at some of the previous onRelease/for loop topics, I'm still stuck. I have 26 buttons for 26 letters in the alphabet. The buttons are defined on the stage already (they look like they're drawn in chalk, oh boy!). I'd like to do a loop to set onRelease for all the buttons. Each button's instance name is a single alphabetic character, which I thought I could use to identify which button was pressed ("A", "B", "C"...). So I set up this loop:

      for (var thing in this) {
      if (this[thing] instanceof Button) {
      // the alphabet button names are one character long
      if (this[thing]._name.length == 1) {
      this[thing].onRelease = function():Void {
      // thought the button name, which is a letter, would be passed as arg
      letterPressed(this._name);
      }
      }
      }
      }

      Unfortunately, the "this" in on release is at level10, not at the button level (it's at _level10, not _level10.A, _level10.B, etc). It's as if the onRelease was not called in the main timeline, and no longer knows what button called it. It's the same as if I directly selected the button in the flash editor, and called on(release) in the actions panel.

      By the way, I did try setting an id into the button within the loop, but that doesn't help, since "this" doesn't point to the right thing.

      If I overtly set onRelease like this:

      A.onRelease = function() { trace(this._name)}

      I get "A", which is what I want. So.....how can I set these in a loop, but have the onRelease behave like it's set in the timeline (which it is), and not as if it's set down in the button? It would be really handy if I could use the for loop, and not have to call 26 separate onReleases. Any help would be appreciated. Thank you.