Access class return value

OK, this is a follow-up to a recent post (for those who might recognize it).

I’m very confused about what I THINK is probably a simple concept. I want to send a value to a class and use the class’s return value. Below is an example, and I want to make sure you understand, THIS IS NOT what I’m actually trying to do – it’s just a very simple example of what I’m not able to do, and if I can answer this question hopefully I can extend the solution to my “real” project.

Here’s my AddFour class, which simply adds four to the number I passed to it:


package {
 public class AddFour { 
  private var _num:Number;
  public function AddFour(num:Number):void {
   _num = num;
   init(_num);
  }
  private function init(_num:Number):Number {
   return _num + 4;
  }
 }
}

My problem is, I don’t know how to get to the returned value. How do I do that?

To wit: In my .fla file, I have this:

var foo:AddFour = new AddFour(7);

If I add a few traces, I see that AddFour successfully adds four to seven to get 11. So far so good.

But what do I do in my .fla file to get a variable whose value is what AddFour returns?

BTW, if I follow the above line in my .fla file with

trace("foo = " + foo);

…my trace is…

foo = [object AddFour]

This makes sense to me. Again, I assume the answer is pretty simple and I’m just missing something fundamental. What I’m looking for is a line of code that will let me define a variable whose value will be the return value of AddFour. (And PLEASE don’t advise me to just do the math in my head. =) )

Thanks!