I would implement it differently:

COMPILE::SWF//assuming this works in SWF
public function inheritDimensions(width:Boolean=true,height:Boolean=true):void{
  if(width){
    this.width = NaN;
  }
  if(height){
    this.height = NaN;
  }
}
COMPILE::JS
public function inheritDimensions(width:Boolean=true,height:Boolean=true):void{
        if(width){
          _width = _explicitWidth = _percentWidth = NaN;
          this.positioner.style.width = null;
        }
        if(height){
          _height = _explicitHeight = _percentHeight = NaN;
          this.positioner.style.height = null;
        }
    // do we need to dispatch an event?
}

> 1.- *I loose ternary operato**rs*. I mean expressions like:  *button.width
> = **condition ? 200 : NaN;*

Like I already said, I think this kind of code is bug-prone, so I don’t share 
your concern.

> 2.- *Lose opportunity to do binding in MXML*. I mean expressions like:
> *button.width
> = "{condition ? 200 : NaN}”*

You can create a subclass of Button in your application with custom setters if 
this is a concern.

> 3.- *Duplicating `style.width` instruction*. In setWidth the
> positioner.style.width is set to "NaNpx" then we reach the
> "setInheritWidth" to remove to null. No collateral problems, but just seems
> poor code.

My implementation solves this problem. Ideally I’d like to solve the problem of 
accessing private vars from utility functions, but that’s another topic.


HTH,
Harbs
> On Dec 27, 2019, at 2:03 PM, Carlos Rovira <[email protected]> wrote:
> 
> public function setInheritWidth(noEvent:Boolean = false):void
> {
> setWidth(NaN);//we need _width = NaN
> COMPILE::JS
> {
> this.positioner.style.width = null;//remove style.width after setWidth sets
> _width to "NaNpx" for JS
> }
> }

Reply via email to