1 Reply Latest reply on Jul 7, 2006 8:54 PM by Newsgroup_User

    actionscript newbie

    Brhaynes75 Level 1
      i'm exploring actionscript for the first time and was exploring some of the templates that Flash offers. I came across a slide animation template with this code in the first frame. can anyone explain it to me?


      // If not defined yet,
      if (isLoaded == undefined) {

      // Routine to move playhead to a new frame
      var updateFrame = function (inc) {

      var newFrame = _currentframe + inc;
      gotoAndStop(newFrame);

      if (_root._currentframe == 1) {
      backBtn._alpha = 50;
      backBtn.enabled = false;
      } else {
      backBtn._alpha = 100;
      backBtn.enabled = true;
      }
      if (_root._currentframe == _root._totalframes) {
      forwardBtn._alpha = 50;
      forwardBtn.enabled = false;
      } else {
      forwardBtn._alpha = 100;
      forwardBtn.enabled = true;
      }
      }


      // When the forward button is pressed
      forwardBtn.onPress = function () {
      updateFrame(1);
      }

      // When the back button is pressed
      backBtn.onPress = function () {
      updateFrame(-1);
      }

      // When the keyboard keys are pressed
      var keyListener = new Object();
      keyListener.onKeyDown = function () {
      if (Key.isDown(37)) {
      // Left
      updateFrame(-1);
      } else if (Key.isDown(38)) {
      // Up
      updateFrame(-(_currentframe-1));
      } else if (Key.isDown(39)) {
      // Right
      updateFrame(1);
      } else if (Key.isDown(40)) {
      // Down
      updateFrame(_totalFrames + 1);
      }
      }
      Key.addListener(keyListener);


      // Call updateFrame at first to get button states correct at start
      updateFrame();
      }

      // Set loaded flag to prevent redefinition
      this.isLoaded = true;
      stop();
        • 1. Re: actionscript newbie
          Level 7
          The isLoaded variable is because the frame containing the code should only
          play once and in case the playback head crossed the frame the code will not
          play twice.

          The updateFrame function sets the appearance of UI buttons based mostly on
          the frame number.

          The other functions are attached to buttons or keys to handle their
          interaction and all seem to call updateFrame.

          --
          Lon Hosford
          www.lonhosford.com
          Flash, Actionscript and Flash Media Server examples:
          http://flashexamples.hosfordusa.com
          May many happy bits flow your way!
          "Brhaynes75" <webforumsuser@macromedia.com> wrote in message
          news:e8i2c0$2eo$1@forums.macromedia.com...
          > i'm exploring actionscript for the first time and was exploring some of
          > the
          > templates that Flash offers. I came across a slide animation template with
          > this
          > code in the first frame. can anyone explain it to me?
          >
          >
          > // If not defined yet,
          > if (isLoaded == undefined) {
          >
          > // Routine to move playhead to a new frame
          > var updateFrame = function (inc) {
          >
          > var newFrame = _currentframe + inc;
          > gotoAndStop(newFrame);
          >
          > if (_root._currentframe == 1) {
          > backBtn._alpha = 50;
          > backBtn.enabled = false;
          > } else {
          > backBtn._alpha = 100;
          > backBtn.enabled = true;
          > }
          > if (_root._currentframe == _root._totalframes) {
          > forwardBtn._alpha = 50;
          > forwardBtn.enabled = false;
          > } else {
          > forwardBtn._alpha = 100;
          > forwardBtn.enabled = true;
          > }
          > }
          >
          >
          > // When the forward button is pressed
          > forwardBtn.onPress = function () {
          > updateFrame(1);
          > }
          >
          > // When the back button is pressed
          > backBtn.onPress = function () {
          > updateFrame(-1);
          > }
          >
          > // When the keyboard keys are pressed
          > var keyListener = new Object();
          > keyListener.onKeyDown = function () {
          > if (Key.isDown(37)) {
          > // Left
          > updateFrame(-1);
          > } else if (Key.isDown(38)) {
          > // Up
          > updateFrame(-(_currentframe-1));
          > } else if (Key.isDown(39)) {
          > // Right
          > updateFrame(1);
          > } else if (Key.isDown(40)) {
          > // Down
          > updateFrame(_totalFrames + 1);
          > }
          > }
          > Key.addListener(keyListener);
          >
          >
          > // Call updateFrame at first to get button states correct at start
          > updateFrame();
          > }
          >
          > // Set loaded flag to prevent redefinition
          > this.isLoaded = true;
          > stop();
          >