Ho appena sviluppato un componente Flex Box, che funge da contenitore di componenti regolari, ma disegna uno sfondo rettangolo arrotondato, con un altro rettangolo arrotondato che indica un livello di riempimento. Per questo ho dovuto ritagliare la sezione superiore che non dovrebbe essere riempita. Disegnare il rettangolo di riempimento all'altezza di riempimento non era un'opzione in quanto gli angoli arrotondati non corrispondevano.
Quello che ho imparato:
- ho creato un componente della tela di canapa solo per disegnare il livello di riempimento con limiti 0/0 e larghezza/altezza del Box
- ho aggiunto quella tela nella casella qui dell'indice 0 via addChildAt()
- a impostare la proprietà includeInLayout false per quella tela dato che non prenda parte alla interfaccia grafica della scatola stessa, ma piuttosto come alcuni riquadro disegno galleggiante sulla cima
- ho poi aggiunto un altro tela come la maschera a quella tela di riempimento (addChild() e imposta m chiedere proprietà)
Ecco il codice:
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
// super
super.updateDisplayList(unscaledWidth, unscaledHeight);
// prep
var g:Graphics = this.graphics;
var fgColor:int = this.getStyle("fillColor");
var bgColor:int = this.getStyle("backgroundFillColor");
var radius:int = this.getStyle("cornerRadius");
// clear
g.clear();
// draw background
g.beginFill(bgColor, 1);
g.drawRoundRect(0, 0, unscaledWidth, unscaledHeight, radius, radius);
g.endFill();
// draw fill level
if (this._fillLevel > 0) {
var fillHeight:int = int(unscaledHeight * this._fillLevel);
// extra component for drawing fill-level, so we can apply mask just to this
if (this._fillLevelCanvas == null) {
this._fillLevelCanvas = new Canvas();
this._fillLevelCanvas.x = 0;
this._fillLevelCanvas.y = 0;
this._fillLevelCanvas.includeInLayout = false;
this.addChildAt(this._fillLevelCanvas, 0);
}
this._fillLevelCanvas.width = unscaledWidth;
this._fillLevelCanvas.height = unscaledHeight;
// mask
if (this._fillLevelMask == null) {
this._fillLevelMask = new Canvas();
this._fillLevelMask.x = 0;
this._fillLevelMask.y = 0;
this._fillLevelCanvas.addChild(this._fillLevelMask);
this._fillLevelCanvas.mask = this._fillLevelMask;
}
this._fillLevelMask.width = this.width;
this._fillLevelMask.height = this.height;
this._fillLevelMask.graphics.beginFill(0xFFFFFF);
this._fillLevelMask.graphics.drawRect(0, this.height-fillHeight, this._fillLevelMask.width, this._fillLevelMask.height);
this._fillLevelMask.graphics.endFill();
this._fillLevelCanvas.graphics.beginFill(fgColor, 1);
this._fillLevelCanvas.graphics.drawRoundRect(0, 0, unscaledWidth, unscaledHeight, radius, radius);
this._fillLevelCanvas.graphics.endFill();
}
}
che i link non funziona per me, forse si vuol dire questa discussione: http://forums.adobe.com/message/47864 # 47864 – Tom