MACROMEDIA FLEX - DEVELOPING COMPONENTS AND THEMES Uživatelský manuál Strana 14

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 36
  • Tabulka s obsahem
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 13
Version#1.0#(May#14,#2009)#
own!width!requiring!the!component!to!update!its!layout,!set!its!children’s!width!
causing!them!to!update!their!layout!and!then!inform!its!parent!that!the!width!
change,!possibly!spawning!even!more!calls!to!other!width!affected!properties!and!
calculations.!!!
Now,!on!the!next!line!we!set!width!again!requiring!all!the!changes!to!be!applied!a!
second!time.!!The!execution!time!has!now!doubled!and!if!the!set!width!occurs!even!
more!times,!the!execution!time!can!jump!dramatically!causing!our!Flash!frame!to!
extend!for!no!good!reason.!!What!we!would!prefer!is!for!all!those!operations!to!
occur!only!once!and!after!the!last!execution!of!a!set!width.!
The!Invalidation‐Validation!cycle!solves!this!problem!by!using!a!flag!system!and!
delaying!the!execution!of!the!required!update!code!until!later.!!Let’s!look!at!the!
width!setter!for!UIComponent!(this!is!partial!code):!
public function set width(value:Number):void {
if(explicitWidth != value) {
explicitWidth = value;
invalidateSize();
}
// other code follows…
Figure'5')' Width'Code'Example'
The!method!first!checks!to!see!if!the!value!changed,!if!not!the!method!ignores!the!
new!value.!!If!the!value!has!changed,!it!stores!the!new!value!and!the!calls!
invalidateSize().!Let’s!look!at!what!the!invalidateSize()!method!does.!
public function invalidateSize():void {
if (!invalidateSizeFlag) {
invalidateSizeFlag = true;
if (parent && UIComponentGlobals.layoutManager)
UIComponentGlobals.layoutManager.invalidateSize(this);
}
}
Figure'6')' Invalidate'Size'Example'
The!invalidateSize()!method!is!a!simple,!but!powerful!method.!!It!first!checks!to!
see!if!invalidateSize()!has!been!called!previously!using!the!invalidateSizeFlag!
value
12
.!!The!first!time!this!method!is!called!(either!during!birth!or!post‐validation),!
the!invalidateSizeFlag!is!false!and!is!set!to!true,!the!method!then!checks!if!we!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12
#The#invalidateSizeFlag#sho uld#b e#considered#an#internal#flag,#one #that#we#should#never#set#
dire ctly.#Later#on#i n#the#Flex#Component#Development#B est#Practi ces#section#we#will# demonstr ate#how#to#
create#our#own#pr operty#fla gs#to#track#the#current# Invalidati on^Validation#property#states#and#these#
should#n ot#be #conf used#with #the#internal#UICompoment#flags.#
Zobrazit stránku 13
1 2 ... 9 10 11 12 13 14 15 16 17 18 19 ... 35 36

Komentáře k této Příručce

Žádné komentáře