Passing optional variables in brackets

:megaman_x:So check this out…

Let’s say I have a function in a class with two required parameters and two optional:



public class Person extends Sprite {
    private var haveToWork:Boolean;
    private var hoursOfSleep:Number;
    private var gotANewVideoGame:Boolean;
    private var gotAHotDate:Boolean;

    public function Person():void {
        //Constructor stuff
    }

    public function areYouHappy(haveToWork:Boolean, hoursOfSleep:Number,
                                           gotANewVideoGame:Boolean = false, 
                                           gotAHotDate:Boolean = false):void {

        //Assign to instance variables
        this.haveToWork = haveToWork;
        this.hoursOfSleep = hoursOfSleep;
        this.gotANewVideoGame = gotANewVideoGame;
        this.gotAHotDate = gotAHotDate;

    }
}

As you can see, this function stores information in an instance of the class… other functions will actually be used to return values.

So right now, to use this function from another class, I would have to do something like this:


var brad:Person = new Person();

brad.areYouHappy(true,8,false,true);

What I would rather do is to pass in optional arguments by name… now I have seen this done before and from what I understand, it would look something like this:


public class Person extends Sprite {
    private var haveToWork:Boolean;
    private var hoursOfSleep:Number;
    private var vars:Object;

    public function Person():void {
        //Constructor stuff
    }

    public function areYouHappy(haveToWork:Boolean, hoursOfSleep:Number,
                                           vars:Object):void {

        //Assign to instance variables
        this.haveToWork = haveToWork;
        this.hoursOfSleep = hoursOfSleep;
        this.gotANewVideoGame = vars.gotANewVideoGame;
        this.gotAHotDate = vars.gotAHotDate;

    }
}

And I think it would be called like this:


var brad:Person = new Person();

brad.areYouHappy(true,8,{gotANewVideoGame:true});

Now for my purposes, I have to call that function two different times:


 var brad:Person = new Person();
 
brad.areYouHappy(true,8,{gotANewVideoGame:true});
.
.
.
//Other stufff happens
.
.
.
 brad.areYouHappy(true,8,{gotAHotDate:true});
 

All of that setup for this question: on the second call of the areYouHappy function, how do I keep the gotANewVideoGame variable from having a false value assigned to it?

Does that make sense at all?