MACROMEDIA FLEX - DEVELOPING COMPONENTS AND THEMES Manuel d'utilisateur Page 34

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 36
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 33
Version#1.0#(May#14,#2009)#
changed!there!is!no!reason!to!run!our!calculations!and!re‐draw!our!UI.!
34
!!If!our!
value!has!changed!then!we!calculate!the!total!value,!set!it!and!then!mark!the!chart!as!
dirty!so!that!when!updateDisplayList()!is!called!we!can!re‐draw!the!chart.!
Once!commitProperties()!is!complete!the!updateDisplayList()!method!is!called!
by!the!LayoutManager!and!we!check!to!see!if!our!chart!flag!has!changed.!!If!the!value!
has!changed,!we!then!draw!the!chart!to!the!UI.!
At!first!glance,!it!may!seem!that!we!have!added!a!lot!of!code!to!do!such!a!simple!
process,!but!by!breaking!out!the!code!into!their!respective!Phases!we!save!ourselves!
a!lot!of!potential!heartache!and!guarantee!much!better!performance!right!out!of!the!
box.!
Using+And+Acce s s in g+Styles+
The!last!best!practice!we!are!going!to!examine!is!accessing!and!setting!styles!in!a!
Flex!component.!!This!will!be!a!brief!examination!of!styles!because!the!Style!system!
in!Flex!deserves!its!own!paper!due!to!the!nature!and!complexity!of!the!provided!
functionality.!In!this!section!we!will!simply!be!looking!at!where!and!when!you!
should!access!the!properties.!
Setting!styles!can!be!done!at!almost!any!time!because!the!setStyle()!method!is!
smart!enough!to!store!values,!determine!if!it!inheriting,!etc.!!Yet,!just!because!you!
can!set!a!style!anywhere,!does!not!mean!that!it’s!a!good!practice.!!!
When!configuring!your!default!styles!for!a!component,!it!may!be!better!to!do!this!
post‐Addition!so!that!you!can!check!to!see!if!the!style!has!been!set!previously,!before!
defining!a!default!property.!One!recommended!location!would!be!in!the!
childrenCreated()!method.!!This!allows!you!to!access!defined!styles!and!set!styles!
on!your!now!created!children.!
Accessing!styles!is!a!different!issue.!!Styles!are!not!defined!until!addingChild()!is!
called!on!the!UIComponent.!This!method!is!responsible!for!looking!up!applied!styles!
via!Themes!and!inheritance.!!If!you!try!to!use!getStyle()!before!then!you!will!have!
very!unpredictable!results.!!This!also!means!that!your!component!must!have!a!
parent!before!you!can!properly!start!accessing!styles!that!have!been!defined.!
Applying+Styles+
It’s!important!to!note!that!styles!should!not!be!applied!(i.e.!rendered)!until!the!
Validation!Phase.!!When!developing!custom!content,!children,!drawing!UI!(such!as!
our!example!in!The!Invalidation‐Validation!Cycle!and!Methods)!we!should!wait!until!
the!updateDisplayList()!method!is!called!so!that!we!can!properly!access!and!then!
render!the!applied!styles!to!our!UI.!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
34
#Remember,#our#commitProperties()#method#may#be #called#by#many#other#property/value#
changes#from#either#our#code#or#the# Framework#co de.##Therefore,#we#alway s#want#to#determin e#what#
has#changed#during#the#last#Invalidation#Phase#before#e xecuting#any#logic.#
Vue de la page 33
1 2 ... 29 30 31 32 33 34 35 36

Commentaires sur ces manuels

Pas de commentaire