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:


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


      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?



        • 1. Re: Returning text from class to project file
          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" ];

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

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