PDA

View Full Version : Property of a property



radgar
April 27th, 2009, 01:08 AM
Hi, I have a question about AS3 I couldn't find any answers.
I'd be glad if you could help me.

I can only explain this by an example; so:
I have 2 classes and one of them includes the other as a getter/setter property:



public class First {
private var _X:Number = 0;
public function get X():Number {
return _X;
}
public function set X(value:Number):void {
_X = value;
}

// some other properties here...

public function First(x:Number) {
this.X = x;
}
}

public class Second {
private var _first:First = new First(0, 0);
public function get first():First {
return _first;
}
public function set first(value:First):void {
_first = value;
ExpectedMethod();
}
public function Second() {}
}

var second:Second = new Second();
//When I execute the following code:
second.first = new First(1, 1); //ExpectedMethod() is fired which is ok.

//I need the following code to return the same result:
second.first.X = 1; //but it does not. ( ExpectedMethod() is NOT fired. )


I know why..
but is there a way to tweak this code to get what I want?

Krilnon
April 27th, 2009, 01:31 AM
You could call ExpectedMethod in get first or set X, depending on what you want to accomplish. You haven't really said what you're trying to do.

radgar
April 27th, 2009, 09:57 AM
Krilnon, what I need is this:
ExpectedMethod() is only fired when second.first is set to a new First() instance.
But, When second.first.X is set; I also need second.first setter method to be executed so the ExpectedMethod() is fired.