2 Replies Latest reply on Dec 4, 2007 10:57 PM by ArthurvR

    Problem with accessing movieclip functions

    ArthurvR
      Hi,

      I just started to learn actionscript. I have a long background in programming and maybe I'm focusing to much on other languages. I tried searching for a solution but couldn't find it.

      I have created a small fla with a movieclip that I want to use as a button. The button movieclip contains several images that I want to change with a funcion. This function is defined in a layer attached to that button movie clip.

      I have the following code in a layer of the complete fla (first frame). The main movie contains several button movieclips named btn11, btn12, btn13 etc

      function init(Void):Void {
      trace("Init");
      currentX=1;
      currentY=1;
      // this function is not called
      this.btn11.setHighlight(true);
      trace("Init finished");
      }

      //----------------------------------
      // event handlers
      //

      var keyListener:Object = new Object();
      keyListener.parent = this;
      keyListener.onKeyDown = function() {
      btnName = "btn"+currentY+currentX;
      code = Key.getCode();
      // soft keys
      // move highlights
      if (code == Key.DOWN) {// down
      // this function is called
      this.parent[btnName].setHighlight(false);
      if (currentY == 9) {
      currentY = 1;
      } else {
      currentY++;
      }
      btnName = "btn"+currentY+currentX;
      this.parent[btnName].setHighlight(true);
      }
      };
      Key.addListener(keyListener);

      init();
      ----------------------------

      The function setHighlight is working when being called from the key Listener but not from the init() function. What am I doing wrong? Is the Movieclip not loaded or initialized yet at that time? How can I wait for that or do I need a complete different approach?