Version#1.0#(May#14,#2009)#
method!does!store!the!value!properly!and!when!the!Addition!phase!begins!the!style!
values!are!be!applied.!!The!problem!with!this!approach!is!that!this!style!could!be!
inherited!up!the!chain,!may!not!be!a!valid!style,!could!be!overwritten!later!in!the!
createChildren(),!etc!and!this!could!cause!potential!unintended!issues!down!the!
road.!
Another!issue!is!that!if!the!developer!does!not!fully!understand!the!Lifecycle,!he!or!
she!may!decide!to!try!and!access!a!property!that!does!not!exist!yet.!!Many!
properties,!especially!children!properties!don’t!exist!until!much!later!in!the!
Lifecycle.!!Sometimes!this!error!becomes!obvious!the!first!time!the!code!is!executed,!
in!others!it!might!not!appear!until!a!specific!order!of!operation!occurs.!
JIT+and+the+Constructor+
Another!reason!construction!should!not!be!used!for!most!of!the!configuration!code!
is!because!the!executed!code!within!the!constructor!of!a!Class!is!always!interpreted!
by!the!Flash!Player.!This!means!that!the!Just‐In‐Time!(JIT)!compilation!process!will!
never!be!applied!to!store!the!constructor!code!as!pre‐compiled!processor!code!for!
future!use.!!Because!the!constructor!will!never!benefit!from!JIT,!if!you!must!perform!
calculations!at!Construction,!you!should!move!this!logic!to!a!separate!method.!
public class MyCustomClass extends DisplayObject
{
public function MyCustomClass() {
this.construct();
}
public function construct():void {
this.addEventListener(FlexEvent.PREINITIALIZE, preinit)
this.addEventListener(FlexEvent.INITIALIZE, init);
}
}
Figure'11')'Using'Metho ds'in'Constructors'
By!moving!this!code!to!a!separate!method!you!are!enabling!the!Flash!Player!the!
ability!to!apply!the!JIT!process!to!your!calculations!if!it!deems!it!as!benefiting!from!
this!process.!!Unfortunately,!you!cannot!guarantee!that!the!JIT!will!be!applied!to!
your!method,!but!by!moving!it!out!of!the!constructor!you!have!the!potential!to!
leverage!the!performance!boost!that!JIT!can!provide.!
32
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
32
#The#Flash#Player#AVM2#uses#a#trace# approach#to#JI T.##This#means#that#all#c ode#is#interpreted#by#the#
AVM#and#during#this#process#the#AVM#tracks#statistics#on#execution#until#the#n umber#of#repeated#
operations#re aches#a#specified#threshold.##Once#the#threshold#is#reached,#the#next#time#the#code#is#
executed#the# JIT#“traces”#th e#path#and#then#marks#if#for#compilation.##The#comp iled#path#is#then#saved#
for#reuse#and #when#the#path#is#requested#again#the#com piled#version#is#used.#
#
For#a#great#explanation#of#how#a#tra cing#JIT#works#read#Mike#Pall’s#explan ation#for#the#Lau#JIT#@#
http://article.gmane.org/gmane.comp.lang.lua.general/44781#
#
Kommentare zu diesen Handbüchern