MACROMEDIA FLEX - DEVELOPING COMPONENTS AND THEMES Bedienungsanleitung Seite 32

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 36
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 31
Version#1.0#(May#14,#2009)#
Using+Dirty+Flags+
The!first!step!in!solving!this!process!is!introducing!the!concept!of!dirty!flags.!!A!dirty!
flag!is!a!Boolean!variable!that!is!marked!true!when!a!value!has!changed.!!We!can!
then!check!the!state!of!the!flag,!and!if!it!is!true!then!we!know!the!corresponding!
value!has!changed!and!is!considered!“dirty”.!!Let’s!look!at!how!we!would!change!the!
code!to!implement!the!dirty!flags:!
[Bindable] public var total:Number;
private var __dataValue:Array;
private var _dataValueDirty:Boolean = false;
public function get dataValue():Array {
return __dataValue;
}
public function set dataValue(value:Array):void {
if(__dataValue != value) {
__dataValue = value;
_dataValueDirty = true;
invalidateProperties();
invalidateDisplayList();
}
}
Figure'13')'Using'Dirty'Flags'Example'
In!Figure!13!‐!Using!Dirty!Flags!Example,!we!have!added!a!new!variable!called!
_dataValueDirty.!!This!Boolean!property!is!our!dirty!flag.!!When!our!dataValue!
changes,!we!now!first!check!to!make!sure!that!the!value!has!changed,!next!we!set!
our!private!property!to!the!new!value,!we!mark!our!flag!as!true!(or!dirty!it)!and!then!
call!our!invalidate!methods,!stating!that!both!our!properties!and!display!list!need!to!
be!validated!on!the!next!pass.!
If!you!remember,!back!in!The!Invalidation!and!Validation!Cycle!section!of!this!paper!
we!examined!how!the!invalidate!methods!mark!the!component!to!be!validated!
during!the!next!validation!pass!by!the!LayoutManager.!!By!setting!our!dirty!flag!and!
then!calling!these!methods!we!have!created!our!separation!between!the!Invalidation!
and!Validation!of!the!dataValue!property!of!our!component.!!This!means!that!our!
dataValue!setter!method!can!be!called!as!many!times!as!needed!during!the!
Invalidation!cycle!and!no!code!will!be!executed!until!our!next!Validation!pass.!!This!
also!guarantees!that!our!drawing!API!calls!will!only!occur!once,!right!before!the!
content!is!drawn!to!screen.!
Implementing+Validation+Methods+
Now!that!we!have!invalidated!our!component,!how!do!we!apply!our!calculations!and!
draw!our!UI!when!the!next!Validation!Phase!occurs?!!Looking!back!at!Component!
Phases:!Validation!(growth!maturity)#we!do!this!by!overriding!the!
commitProperties()!and!updateDisplayList()!methods:!
Seitenansicht 31
1 2 ... 27 28 29 30 31 32 33 34 35 36

Kommentare zu diesen Handbüchern

Keine Kommentare