March 2006


just changed

CODE:
  1. delete __instance;

to

CODE:
  1. __instance = null;

link to the as3 templates

http://xperiments.lennel.org/AS3templates.tar

In flex 1.5 when i in mxml i assigned a component a model i did not care if that model existed or not. it failed silently and flex did what it did, bound correctly and the rest. the 8.5 runtime is not so forgiving, and i like binding my models in mxml. hence i had to start using creationpolicy differently than in the past. now i only create object when i need them and when i have all the necesary information. in the past we would only look at creationPolicy when the view was rendering too slow due too many displayobjects being rendered at once.

anyway. in flex 2 if you do this

XML:
  1. <s:SomeComponent creationPolicy="none"/>

then when you need the component you would do this

CODE:
  1. this.createComponentsFromDescriptors(true);

so whats happening in the background is the compiler creates code that looks something like this:

CODE:
  1. import mx.core.UIComponentDescriptor;
  2. import org.lennel.descriptors.SomeComponent;
  3. private function createSomeChildren():void
  4. {
  5. //I COULD NOT GET CUSTOM ARGUMENTS TO WORK
  6. var args:Object = {};
  7. var descriptor:UIComponentDescriptor = new UIComponentDescriptor(args);
  8. // the object it will be attached to
  9. descriptor.document = this;
  10. //the class the descriptor is going to create for me
  11. descriptor.type = org.lennel.descriptors.SomeComponent;
  12. this.createComponentFromDescriptor(descriptor,true);
  13.  
  14. }

so if creation policy is set to auto all the descriptors are called at once, if Q'd in a Q, and well you should get the idea now. notice i use UIDescriptor.
see: livedocs

a new feature of flex 2 is "view" states whereby i can layout multiple views on the same component using mxml (or actionscript) and change state by setting the currentState property on my view. you can also specify which transitions to use etc when switching from one state to another.
viewstacks in flex 1.5 (and 2) sortoff offer the same functionality.

in flex 1.5 some of the people who work with me tried to create 40 switcing icons that switched between 2 states.they quickly discovered this was a bad idea since all the movieclips got created at once, then the flex framework kicks in with its layout logic, so suddenly the time it took before the user could see a screen jumped from 1 second to 8 seconds. so the next approach was adjusting the creationPolicy, but this let them down an axis of evil (creationpolicy is not always asĀ  straightforward as expected). so what they did was create the clip in flex and use the embed directive. problem solved.
(this could have been done in flex 2 by creating a mxml component with 2 states.)

this example however highlights a limitation of viewstatcks in the past (i have not looked into the dynamics of viewstacks in flex2 so am not certain if all the views gets created immediatly but i suspect so) and maybe in the present. in contrast to this (view) states add and remove the clips as is needed. this is awsome in my opinion. also the zorn plugin for eclipse allows you to look at states independently when designing a form. its just been pointed out to me as well that the design view in zorn allows you to toggle between viewstacks as well

An advantage of building your unit tests as you develop and tying these tests to some application entry point (a mx:Application tag for flex or a movieClip in a AS3 project) is that the eclipse editor uses incremental compilation to show your errors to you. thus developing something that exists in isolation and gets used nowhere won't give you proper feedback. having unit tests solves this problem nicely since every class you are writing has a test and every test is linked to the main test runner thus you can be garunteed that every peice of code you write is somehow imported and compilled.