!
©!2009!DevelopmentArc!LLC,!All!rights!reserved.!
private var _chartDirty:Boolean = false;
override protected function commitProperties():void {
super.commitProperties();
if(_dataValueDirty) {
_dataValueDirty = false;
// calculate the total
var len:int = __dataValue.length;
var _total:Number = 0;
for(var i:uint=0; i < len; i++) {
_total += Number(__dataValue[i]);
}
// set the total
total = _total;
_chartDirty= true;
}
}
override protected function updateDisplayList(
unscaledWidth:Number,
unscaledHeight:Number):void {
super.updateDisplayList(unscaledWidth, unscaledHeight);
if(_chartDirty) {
_chartDirty= false;
// draw the data
drawChart();
}
}
Figure'14')'Overri ding't he'Validation'Me thods'Exam ple'
The!validation!methods!are!always!called!in!an!explicit!order:!commitProperties(),!
measure(),!layoutChrome(),!and!finally!updateDisplayList().!!As!we!have!
previously!mentioned,!this!order!is!important!because!calculations!and!properties!
set!in!the!commitProperties()!may!affect!the!size!or!the!display!list.!!!
Looking!at!Figure!14!‐!Overriding!the!Validation!Methods!Example,!its!possible!that!
we!may!need!the!total!value!to!be!drawn!or!updated!in!the!display!list,!so!it!should!
be!calculated!first.!!This!is!why!we!use!the!invalidate!methods.!!Because!we!need!to!
calculate!a!total!and!also!draw!our!chart!we!need!to!make!sure!that!both!
invalidateProperites()!and!invalidateDisplayList()!are!called!by!the!setter!in!
Figure!13!‐!Using!Dirty!Flags!Example#so!that!commitProperties()!and!then!
updateDisplayList()!are!called.!
When!commitProperties()!is!called,!we!check!to!see!if!the!_dataValueDirty!flag!
has!been!set!to!true.!!We!want!to!make!this!check!because!if!the!value!has!not!
Komentarze do niniejszej Instrukcji