I am trying to implement a forms like model in flash mx 2004. I have two classes, Container and Component. The Container contains many instances of Component. Each time an instance of Component is instantiated I assign a method pointer to it that points back to a method on Container called "onComplete()". When the Component is finished formatting itself, it calls the method that is assigned to it's "onCompleteCallback" function member. Then inside Container.onComplete I use the keyword 'this' but this refers to the Component object and not the Container. I find this very strange and wonder if this is a bug compared to other OO languages. If it is not how do I reference the Container from within it's own method?
Here is some code to show what I got.
I thought of adding a member to the Component class that points back to the Container and then using that within the onComplete() method of Container, but I believe that this compromises encapsulation of that object because you would have to know about the Component class to understand the Container's reference to this.container.processing rather then this.processing.
Thanks for any help I can get on the subject.
Here is some code to show what I got.
Code:
class Container {
private var processing:Boolean = false;
function Container() {}
function onComplete(object:Component) {
// Inside here the keyword 'this' refers to the instance
// of Component rather then the instance of Container.
// Since I can't use this, what keyword would I use to
// reference this instance of the Container class?
}
}
class Component {
private var onCompleteCallback:Function
function Component(callback:Function) {
this.onCompleteCallback = callback;
}
function format() {
this.onCompleteCallback(this);
}
}
I thought of adding a member to the Component class that points back to the Container and then using that within the onComplete() method of Container, but I believe that this compromises encapsulation of that object because you would have to know about the Component class to understand the Container's reference to this.container.processing rather then this.processing.
Thanks for any help I can get on the subject.