1 Reply Latest reply on Sep 29, 2008 7:31 PM by theLoggerGuy

    Returning text from class to project file

    BudHud Level 1
      I want to return more than one string result from a class file to a project file.

      Examples below:

      THE CLASS FILE:

      public function sayHello():String
      {
      result = "This is the first idea I have. ";
      return result;
      }

      THE PROGRAM FILE:

      private function initApp():void
      {
      var myTexter:Texter = new Texter;

      output1.text = myTexter.sayHello();

      This works fine into output1.text.

      How can I use the class function sayHello() to return a second result, this time into output2.text within the initApp project function?

      }

      Thanks,

      BH
        • 1. Re: Returning text from class to project file
          theLoggerGuy Level 1
          The simple answer is: you can't. Not very useful to you though. After thinking about it for a while I find that there is a surprisingly high number of ways to answer this, but I'll pick one (and it's not great).

          In your class your function sayHello() does only one thing. It should stay that way. If you want to return something else then write another function: eg., sayGoodbye(). However, if you're hell-bent on returning more than one thing from a function then just return an array (or better yet a custom data object).

          eg Class:
          public function sayManyGreetings( ): Array
          {
          return [ "Hello", "Bonjour", "Guten tag", "G'Day" ];
          }

          Main:
          private function initApp():void
          {
          var myTexter: Texter = new Texter;

          output1.text = myTexter.sayManyGreetings[ 0 ];
          output2.text = myTexter.sayManyGreetings[ 1 ];
          }