MACROMEDIA FLEX - DEVELOPING COMPONENTS AND THEMES Manual do Utilizador Página 15

  • Descarregar
  • Adicionar aos meus manuais
  • Imprimir
  • Página
    / 36
  • Índice
  • MARCADORES
  • Avaliado. / 5. Com base em avaliações de clientes
Vista de página 14
UNDERSTANDING+THE+FLEX+3+COMPONENT+AND+FRAMEWORK+LIFECYCLE!
15!
!
©!2009!DevelopmentArc!LLC,!All!rights!reserved.!
have!a!parent!and!then!registers!itself!with!the!LayoutManager!instance
13
.!!If!we!
have!called!invalidateSize()!previously,!and!have!not!run!a!validation!phase!yet,!
then!we!don’t!need!to!worry!about!registering!with!the!layoutManager!!because!we!
have!already!registered!for!the!size!to!be!validated!during!the!next!Validation!pass.!!
We!can!now!call!set!width!on!our!Button!as!many!times!as!we!want!before!the!next!
validation!pass!and!performance!will!not!be!hindered.!
Now!that!our!component!is!registered!with!the!LayoutManager,!some!pretty!
ingenious!code!is!executed.!What!that!LayoutManager!does,!is!it!uses!the!
callLater()!method!on!a!hidden!UIComponent!instance!to!execute!the!validation!
phase!once!the!next!Event.RENDER!event!is!dispatched!from!the!stage.!!If!you!recall!
from!Sean!Christmann’s!article,!the!RENDER!event!is!dispatched!to!allow!user!code!to!
be!executed!just!before!the!Flash!Player!draws!the!display!stack!to!screen.!By!
running!the!validation!phase!after!the!RENDER!event!guarantees!us!that!this!is!the!
last!possible!code!to!be!executed!before!the!screen!is!rendered
14
.!!!
The!LayoutManager!acts!as!a!queuing!system,!tracking!all!the!components!that!
register!invalidation!changes!before!the!next!RENDER!pass.!When!the!LayoutManager!
gets!the!RENDER!event,!it!checks!to!see!what!components!have!registered!with!it!
during!the!invalidation!phase!and!then!begins!executing!the!validation!phase!on!
those!objects.!!If!the!LayoutManager!is!in!the!process!of!executing!validation!on!a!set!
of!components!and!new!components!register!with!the!LayoutManager,!these!new!
components!will!be!queued!for!the!next!RENDER!pass.!!This!helps!prevent!an!endless!
cycle!of!updates!during!a!single!pass.!
The!process!of!Invalidation!and!Validation!is!a!cycle!because!any!time!a!property!
changes!it!invalidates!the!component;!the!validation!process!must!then!be!executed!
again!to!put!the!component!back!into!a!valid!state.!
The+Three+Types+Of+Invalidation+
Going!back!to!our!Button!example,!during!the!first!Invalidation!phase!(called!during!
the!Initialization!phase)!we!call!the!three!invalidation!methods:!
invalidateProperties(),!invalidateSize(),!!and!invalidateDisplayList().!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
13#The#reason#the#code#checks#for#a#parent#first,# is#to#determine#if#the#component# is#currently#on#the#
disp lay#stack.##If#the#co mponent# does# not#have#a#parent#then#there#is#no#reason#to#run#these#calculations#
because#we#w ill#no t#be#rendered#on#sc reen. ##
14
#If#we#return#to#Sean#C hristmann’s#blog#post#about#the#AVM2#Ma rshal#frame#sy stem#the#benefit#of#
executin g#the#validatio n#on#the#render#pass#become s#more#apparent.##Sean’s#“Flash#frames#synthesized#
from#AV M2#slices”#diagram#clearly#shows# that#the#user#actio n#is#executed#twice#for#every#invalidate#
action#at#25#frames#per#second.#In#the#Flex#Framework#the#invalidate#action#diagrammed#by#Sean#
corresponds#to#the#Flex#validation#ph ase.##If#the#Flex#Fra mework#did#not#wa it#for#the#RENDER#event#then#
the# validation#cod e#would#be#exe cuted#twice#before#the#c ontent#was#actually#rendered,#potentially#
causing#performance#issues #and#undue#calculations #triggered#by#the#first#user#a ction#and#then#
invalidated#again#by#the#sec ond#user#action.##In#the#25#frame s#exa mple #we#would#only#want#the#second#
user#action’s# chan ges#t o#be#applied#during #the#validation#phase.#
Vista de página 14
1 2 ... 10 11 12 13 14 15 16 17 18 19 20 ... 35 36

Comentários a estes Manuais

Sem comentários