2 Replies Latest reply on May 20, 2006 9:56 AM by Newsgroup_User

    Help with this code, please?

    Angyl Level 1
      I've had this code working before in other projects, but for some reason it's not working now in this new one. Can anyone see the problem?

      There's a "Button1" instance on the stage and the Actionscript for the frame has this:

      Button1.onRelease = b1release() {
      var my_valid_frames:Array = new Array(2,4,6);

      function b1release() {
      var temp_frame:Number = my_valid_frames[random(my_valid_frames.length)]
      this.gotoAndPlay(temp_frame);
      }


      When you press the button, absolutely nothing happens.
        • 1. Re: Help with this code, please?
          blemmo Level 1
          I doubt that this code ever worked. You're mixing 2 things up here:

          Button1.onRelease = function() {
          var my_valid_frames:Array = new Array(2,4,6);
          }

          This the 'inline' function way, you create a (nameless) function 'on the fly' and define it right away.
          And then there's

          Button1.onRelease = b1release;
          function b1release() {
          var temp_frame:Number = my_valid_frames[random(my_valid_frames.length)]
          this.gotoAndPlay(temp_frame);
          }

          where a named function is assigned to onRelease, which is defined seperately. Note that there are no brackets ( ) in the assignment.

          Both ways are fine, but not at the same time.

          hth,
          blemmo
          • 2. Re: Help with this code, please?
            Level 7
            >>When you press the button, absolutely nothing happens.

            Right... your code is a bit messed up.

            You can't define function b1release() inside of the button's onRelease...
            that is just not going to work. I'm not exactly sure what you're trying to
            do here, but something like this is more appropriate:

            Button1.onRelease = b1Release;
            b1Release = function(){
            var my_valid_frames:Array = new Array(2,4,6);
            var temp_frame:Number = my_valid_frames[random(my_valid_frames.length)]
            this.gotoAndPlay(temp_frame);
            }



            --
            Dave -
            Adobe Community Expert
            www.blurredistinction.com
            www.macromedia.com/support/forums/team_macromedia/