Flash Layout Engine in Reflex



As a component platform Reflex is built on a foundation of core libraries and utilities. Because of the unique culture of the project most of these solutions are independently useful to the Flash developer. Its layout engine is one of Reflex’s profitable solutions and can structure the visual flow of any member of ActionScript’s display list.

The following demo illustrates one of the default layout algorithms in Reflex, named Dock (notice the minimal use of containers used to achieve the structure). Click and drag to resize:

Layout Laid Out

Maybe one of the first things you noticed while playing with the demo is that container’s just can’t get smaller than their children. This and other more subtle behaviors make up the physics of layout, the rules that Reflex embodies and simplifies in just 3 core classes: ILayout, ILayoutAlgorithm and the RenderEvent.


ILayout

A Layout object wraps any DisplayObject in Flash and provides most of the properties for a given layout system, such as minimum and maximum widths and heights. The demo above is made up of Flash-designed MovieClips and Sprites, no special base container class, creating Block layout’s that point to each. Block extends Layout and is the default layout system for components, providing various width/height features, margins, padding and other common properties for dividing the screen into rectangular sections. Other ILayout implementations may be created to easily support different layout systems, such as 3D.


ILayoutAlgorithm

One of the most important members of any Layout object is the algorithm. With each layout system comes a variety of supporting layout algorithms, defining the rules by which a specific container lays out its children. Through the Block-based layout system, the example above takes advantage of the specific algorithm Dock. This algorithm aligns children of a container to the LEFT, TOP, RIGHT, BOTTOM or FILL based on their dock and tile properties and allows a mixed layout within a single container. Other algorithms position and size children DisplayObject’s uniformly, such as in a stack or a row.


RenderEvent

Normally laying out a screen can be complicated because children affect the size of their container and containers determine the position and size their children. The driving force in Reflex’s layout engine is, by itself, a stand alone utility ideal for managing the “layout cycle”. RenderEvent isn’t very complicated but it simplifies the layout process and greatly increases performance. This is made possible in 3 ways:

  1. delaying layout computation to just before each screen redraw consolidates all of the property changes that affect both children and container
  2. dividing layout into two phases, where the measure phase allows a container to calculate its minimum (and maximum) size based on its contents, and the layout phase runs the algorithm that finally place those contents
  3. allowing each phase to run in order from the lowest to the highest depth in the display list ancestry (in the case of measure) or from the highest to the lowest depth (in the case of layout). For example, Flash’s stage and root would measure last, and layout first, then the children of root will layout, then their first-level children and so on. The reason for this feature is a little more involved but it makes a huge difference in performance


Contribution

Fortunately it’s very easy to customize display list layout by creating new layout algorithms. There are only two methods required, the measure() and the layout() methods, and these are automatically invoked precisely when they need to be. Robert Taylor got involved in the code and within an afternoon had built several of his own layout algorithms, complete with custom behaviors and tweening. Reflex as a platform offers a variety of components and solutions, but if layout is where your interests lie you can contribute without using or understanding anything else in the framework. Perhaps the best part is, because it works with any kind of DisplayObject, Reflex’s layout engine can be used in Flex, Flash or most any other ActionScript 3 environment. It’s universal!



18 Responses to “Flash Layout Engine in Reflex”

  1. felix says:

    Sounds great! Is the code available?

  2. xtyler says:

    Demo-code added to the right-click menu of the example, and is dependent on the Reflex library at http://github.com/xtyler/reflex

  3. julien says:

    very nice stuff! thanks for sharing

  4. M.Althoff says:

    Universal? Just had a sneak peak into code and found alot of bindings and other compiler directives used. Isn’t that only possible with the Flex Framework ? Does this project compares with Java LayoutManagers? Great work anyways, looks promising…

  5. am says:

    Nice work!
    Could you provide a simple example in Flash IDE?

  6. I’ve got it working with flash CS3. I’ve extracted PropertyChangeEvent and PropertyChangeEventKind from flight-framework source at code.google. I’ve cleared initial errors by changing ILayout implementation in Layout to match interface (replacing public variables with setters). BoxGraphic is not included in view source so i created movieclip with rectangle inside and set linkage to BoxGraphic.

  7. Awesome! Soon I’ll check it’s details.

  8. xtyler says:

    M. – [Bindable] properties are used as a shortcut during current development but will have to be replaced with getter/setters to support the Flash IDE. Reflex uses the Flight Framework binding solutions.

    Tomasz – that’s awesome! You really got your hands dirty, keep up the good work.

    The Reflex team is in the midst of rapid development to prepare for upcoming conferences and demonstrations, so we’re neglecting select features at times, such as full Flash Professional support. We’ll get back to it soon.

  9. James Ward says:

    Wow! That demo loaded so fast that I initially thought it was a screenshot of the demo! Nice work!

  10. Sylvain Lecoy says:

    Did you notice that with Flex Builder 4 when we Eporting Release Build (optimized SWF or Adobe AIR File) the demo doesn’t work anymore ?

  11. Aargh, would really love to change some snowy northern swedish days to sunny and relaxed californian ones..! Good luck with your 360 Flex presentation! Looking forward to follow (and maybe somehow contribute) to the Reflex progress!

  12. Glidias says:

    I’ve peeked into the code and with the exception of ScrollBlock in the reflex.layout package, the rest of the layout classes do not require any Binding dependencies whatsoever, which makes this quite easy to extract out and integrate into a reusable BlockBehaviour class that can be applied to any display object (or IBoxModel-based) display for my own collection . After all, I need some basic dock and center fill liquid layout functionality, and this package, though it seems not fully incomplete in some parts (a bit of to-dos), can help in that area.

  13. xtyler says:

    I’m glad you were able to get in and use this! My friend Rob Taylor has already developed a suite of layout algorithms for his own project and doesn’t use anything else from the framework successfully. It’s a good test of the separation in Reflex.

    The Block class is already a reusable piece that will target any DisplayObject, you won’t need to do any extra work to create a “BlockBehavior”. Behaviors are specifically interactive elements for components, while Layouts, Skins etc are other types of reusable systems.

  14. Glidias says:

    I know Blocks can be used standalone. BlockBehaviour was just a standalone adaptor wrapper because my API uses a specific interface-method activate(target:*):void & destroy():void over a target object, which is pretty archaic/boiler-plate heavy on hindsight (What was i thinking?). I’d definitely have to refactor that to using a pure “target” setter as the standard (where setting target to ‘null disposes off the block/behaviour’s listeners), and therefore eliminate the interface dependencies and allow for cross-platform ease. In fact, the benefit of not using interfaces at all to set targets for behaviours is even better because some behaviour targets may not necessarily be InteractiveObjects. Without an interface, the coder is free to create ANY class with set target(val:MyOwnRequiredType), without resorting to casting. It’s simply assumed there’s a ‘target’ setter for such classes..

    It would be cool to allow Blocks the option to also bind their width and height properties to other properties of the target component, if required (since not all DisplayObjects’ width/height values reflect the measured width/height settings used for layouts).

  15. Scott says:

    Sorry if this is obvious but where is the reflex.swc?

  16. xtyler says:

    Scott, the Reflex initial website has finally been released and should have some additional information there. http://www.reflex.io

  17. Awesom framework! :)

    Do you have a FLA wherea all components are inluded? :)

    That’s very nice also, save many times :)

  18. Scott says:

    The BoxGraphic isn’t included in the demo folder by the looks of things.

    Cheers,

    Scott

Leave a Reply

  • drugs hair loss
  • antibiotic
  • side effects of antibiotics
  • nexium health
  • new medication for cancer treatment
  • congestive heart failure overview
  • canada cialis generic
  • appetite suppressant
  • pain med without prescription
  • buspar online
  • medication pediatric insomnia
  • very cheap viagra
  • increase womens sex drive
  • lowest price generic viagra
  • buying online viagra
  • cheap alcoholism treatment
  • information on ambien
  • celexa and anxiety
  • lamictal withdrawal
  • celebrex capsules
  • diabetes treatment
  • pain meds no prescription
  • weight loss food
  • body building diets
  • drugs fda
  • anti-fungal
  • pharmacy allegra
  • parkinsons disease medication
  • reducing high blood pressure
  • how does viagra work?
  • medications for depression
  • clomid cycles
  • best male enhancement drugs
  • bodybuilding nutrition buy supplements
  • natural dog health
  • next day medication
  • herbal weight loss products
  • weight loss nutrition
  • famvir dose
  • cheap antibiotics
  • order zoloft
  • zyrtec medication
  • acne skin treatment
  • prescription pain medicines
  • wal mart pharmacy
  • cheap nolvadex
  • online phentermine online prescription
  • tips for insomnia
  • stress medicine for cats
  • canada online drug stores
  • osteoporosis evista
  • viagra order online
  • drugs online no prescription
  • cheap birth control online
  • newest bodybuilding products
  • treating diabetes
  • deep sleep disorder
  • celexa buy
  • how to lose asthma
  • rheumatoid arthritis medications
  • xanax sales
  • high cholesterol diet
  • anxiety order
  • canada pharmacy
  • vitamine guide for dogs
  • different treatments of alcoholism
  • online apotheke
  • hypertension and low heart rate medications
  • treatment for hepatitis c
  • list of blood pressure medicines
  • information on sleeping aids
  • cheap antibiotics
  • bust enlarge
  • how to get viagra prescription
  • muscle nerve pain
  • mens health 40
  • hair re-growth
  • acai berry products
  • tips for gaining muscle mass
  • where to order soma
  • baby acne
  • cialis 10
  • viagra discount online
  • sleeping problems uk
  • buy cialis without a prescription
  • free stop smoking ways
  • womens health menopause
  • how to relieve ear pain
  • hoodia fast
  • aldactone medication
  • uric acid remedies
  • generic zyrtec
  • hangover help
  • buy ambien online cheap
  • lexapro paxil
  • sinus infection med
  • dog lose weight
  • order birth control
  • anti-fungal
  • neck pain
  • psoriasis treatments
  • cialis on line
  • pravastatin
  • new heart attack drugs
  • how to cure diarrhea
  • online pharmacy ratings
  • generic allegra
  • ativan prescription
  • prescription for severe stomach pain
  • medical irritable bowel
  • teeth whitening buy
  • women's hair loss remedie
  • why most people benefit from antidepressants
  • pain cure
  • klonopin anxiety
  • hiv medications
  • prevent itching
  • xanax buy on line
  • nolvadex no prescription
  • xanax perscription
  • anxiety disorder
  • canadian arthritis medication
  • menstrual cramp pain
  • stomach ulcer pain
  • dietary supplement
  • acai berry pills
  • viagra coverage california
  • cures for depression
  • lower your blood pressure
  • treatment of psoriasis
  • cold sores help
  • buy Lozol
  • high blood pressure and treatment
  • pet health care
  • diet supplements distributors
  • cyclophosphamide
  • get klonopin
  • anti-fungal
  • shoulder arthritis
  • cheap caffeine
  • acne tips
  • free prescription medication
  • cat anxiety medicine
  • hepatitis c treatments
  • medication for severe chronic pain
  • order prozac
  • blue pills
  • parkinson's meds
  • anti malaria drugs
  • diet pills online
  • online drug store
  • vascular edema
  • online valium no prescription
  • help stop smoking
  • hydrochlorothiazide generic
  • medication prices
  • cold v flu
  • congestive heart failure med
  • blue pills
  • kidney cancer drugs
  • chlamydia cures
  • vitamin c for dogs
  • oral diabetes medication
  • us drugstore
  • ultimate weight loss
  • list pain meds
  • cialis best on-line drugstore
  • ambien sample
  • new treatment for heart failure
  • pet meds on line
  • buy clomid
  • cheap cialis site
  • bodybuilding nutrition
  • small penis
  • ambien dosages
  • treatments and cures for epilepsy
  • natural weight loss supplements
  • dry skin treatment
  • online order ambien
  • symptoms of stop smoking
  • blood pressure treatment drugs
  • diclofenac dosage
  • helping high blood pressure
  • bronchitis medications
  • antibiotics safe for dogs
  • immune system strengthen
  • best weight loss pills
  • usa pharmacy
  • allied health
  • colon cancer treatment
  • drug treatment for alcoholism
  • tramadol very cheap
  • early prostate cancer treatment
  • side effects claritin
  • retin a cheap
  • online pharmacies in mexico
  • new treatment for allergies
  • prescription drug prices
  • generic plavix
  • buying viagra prescription