Continuing with the ubSquare example, now let's suppose that I want to scale my square whenever it becomes visible. Well, _visible is a property of the class, just like side was so how about adding some code like:
//at the top with _side private var __visible:Boolean = true; //with the side getter and setters public function get _visible():Boolean{ trace("in ubSquare get _visible"); return this.__visible; } public function set _visible(newVis:Boolean):Void{ trace("in ubSquare set _visible"); this.__visible = newVis; this._visible = newVis; }
This is just like what I did for side, except that I can't just change my private __visible property and expect the movieclip to change, so I add the last line to tell the movieclip to actually change its visibility.
There are two problems with this:
- If I put a line like:
this.mySquare_ubS._visible = false;
in my tester, the set function is not called. - If I put a line like
this._visible = true;
in my scale method, I get 256 levels of recursion since the set for _visible calls itself.
this._visible = newVis;
to
setProperty(this, _visible, newVis);
The output becomes:
scale making movieclip visible true in ubSquare set _visible in ubSquare get _visible
This, of course, begs three questions:
- what is the point of writing a setter for _visible if it can be avoided by using a (deprecated) setProperty operation?
- why is a get _visible call made when I set _visible? The line in the scale method (this._visible = true) calls both the setter and the getter. I was sure I had a good link that explained why but cannot for the life of me find it now.
- how do I solve the first problem which was the important one? I want to be able to notice when anything makes my square visible, not just when some of my own class code does.
No comments:
Post a Comment