MACROMEDIA FLEX - DEVELOPING COMPONENTS AND THEMES Instrukcja Użytkownika Strona 10

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 36
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 9
Version#1.0#(May#14,#2009)#
Looking!at!FlexSprite’s!constructor!all!it!does!is!define!the!name!property!with!a!
unique!string!value.!
5
!!Since!that!is!all!that!happens!in!the!FlexSprite!constructor!
we!can!step!down!to!UIComponent!constructor.!!UIComponent!does!a!bit!more!during!
construction,!but!not!a!lot.!!It!sets!up!the!focus!management,!starts!tracking!its!own!
add!and!remove!events!(for!delegation!reasons),!sets!up!listening!for!focus!events,!
keyboard!events,!defines!its!reference!to!the!Resource!Manager!(used!for!
localization)!and!then!stores!a!private!version!of!the!components!current!width!and!
height!that!may!have!been!defined!on!the!super!Class.!!Again,!very!little!is!done.!!No!
layout,!no!styles,!no!children!creation,!etc.!
Finally,!we!get!back!to!the!Button!Class.!!All!Button!does!is!register!to!the!
MouseEvents!to!handle!user!interaction.!!That’s!it,!that’s!all.!!!!
For!more!details!about!using!the!constructor!in!your!own!component!development,!
we!discuss!best!practices!and!recommendations!in!the!section!Using!Construction,!
later!in!this!document.!Now!that!we!are!constructed,!what!starts!the!next!phase?!!!
Component+Phases:+Addition+(birth)+
The!Addition!phase!occurs!when!you!add!the!component!to!a!parent!component.:!
this.addChild(myButton); // the addition phase begins
Figure'2')' Add'C hild'Example'
The!process!of!adding!the!component!to!the!parent!executes!a!huge!amount!of!
functionality!on!the!parent!and!this!is!where!the!lifecycle!really!kicks!into!high!gear.!!
Let’s!look!at!UIComponent’s!addChild()!method!and!how!it!defines!the!Addition!
phase.!!!
The!addChild()!method!is!broken!down!into!three!sub‐method!calls:!
addingChild(),!$addChild()!and!childAdded().!!The!pattern!of!breaking!phases!
down!into!sub‐steps!is!a!common!one!within!the!Flex!Framework.!!By!breaking!
complex!processes!into!smaller!sections!helps!enable!better!control!over!the!entire!
process.!!We!will!delve!more!into!this!ability!later!on!in!the!following!lifecycle!
sections!and!also!in!the!Flex!Component!Development!Best!Practices!section.!!
When!the!addChild()!method!is!called,!it!first!executes!the!addingChild()!method
6
.!
The!addingChild()!method!does!a!lot!of!the!heavy!lifting!for!us,!such!as!setting!the!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5
#When#you#launch#a#Flex#app#and#set#a#breakpoint#to#view#the#current#display#stack#i n#the#Flex#
debugge r,#you#will #see#comp onents#referenced#as#“Button12”#or#“ComboBox4”#in#the#Flex#component#
hierarchy.#This#is#the#name#value#of#the#component.#The#FlexSprite’s#constructor #is#where#the#name#
of#the#component#is#defined .#Flex#uses#a#utility#called#NameUtil#that#takes#the#cl ass#name#and#appends#
a#unique#counter#value#depending#upon#how#many#instances#of#the#class#name#have#been#previously#
created.# #“Button12”#would#be#the#12
th
#button#creat ed#in#the#applicatio n.#
#
6
#In#addChild(),#the#method#first#checks#to#see#if#this#addition#is #a#re^parenting#of# the#component,#if#s o#
it#removes#the#compon ent#from#the#previous#parent#first#before#attempting#to#add#the#child#to#the#new#
parent.#In#our#example,#the#Button#was#just#crea ted#so#no# previ ous#parent#exists.##The#method#sets#the#
child’s#index#position#and#then#executes#the#addingChild()#metho d.###
Przeglądanie stron 9
1 2 ... 5 6 7 8 9 10 11 12 13 14 15 ... 35 36

Komentarze do niniejszej Instrukcji

Brak uwag