4 Replies Latest reply on Sep 28, 2008 8:42 PM by g-s-b

    Incrementing Within A Class

    BudHud
      I have this class, and I want to click a button within the main program and access the class, from there call the first string, click the same button a second time in the main program and call the second string from within the class, a third time and the third string. Is it possible?

      package Edit
      {
      public class Texter
      {
      public var result:String;
      public var i:int;

      public function Greeter()
      {
      }

      public function sayHello():String
      {
      if (i == 0)
      {
      result = "This is text one. ";
      }
      else if (i == 1)
      { result = "Here is the second string.";
      }
      else if (i == 2)
      {
      result = "This is string number three.";
      }
      return result;
      }
      }
      }

      Thanks,

      BudHud
        • 1. Incrementing Within A Class
          g-s-b
          public static var i:int = 0;

          • 2. Re: Incrementing Within A Class
            Level 7

            "BudHud" <webforumsuser@macromedia.com> wrote in message
            news:gbmvtc$eij$1@forums.macromedia.com...
            >I have this class, and I want to click a button within the main program and
            > access the class, from there call the first string, click the same button
            > a
            > second time in the main program and call the second string from within the
            > class, a third time and the third string. Is it possible?

            I'd maybe do it like this:

            package Edit
            {
            public class Texter
            {
            [Bindable]
            public var result:String = '';

            public function sayHello():void
            {
            switch (result) {
            case '':
            result = 'This is text one.';
            return;
            case 'This is text one.';
            result='Here is the second string.';
            return;
            //if you get here, result doesn't have any of the above
            result='This is the third string';
            }
            }
            }


            -OR-

            package Edit
            {
            public class Texter
            {
            private var _result:String;
            private var i:int=0;
            private static var strings:Array ["This is text one. ", "Here is the
            second string.", "This is string number three."];

            public function sayHello():String
            {
            _result = strings ;
            if (i<strings.length-1) {
            i++;
            } else {
            //wrap
            i=0;
            }
            }
            }
            }


            • 3. Re: Incrementing Within A Class
              BudHud Level 1
              Thank you Greg,

              BH
              • 4. Re: Incrementing Within A Class
                g-s-b Level 1
                "Thank you Greg,"

                You are welcome.