explorers’ club


Quick hint: Complex Component Development in MXML
Thursday, April 23, 2009, 6:36 pm
Filed under: actionScript, components, development, flex, tutorial | Tags: , , , , ,

Assume that you are creating a component in MXML such as some multi-state cell renderer or something that implements IDataRenderer.

All mx.core.Container subclasses have a convenient little event hook called dataChange.  Anytime you set a value to the data property, the component dispatches an event of type FlexEvent.DATA_CHANGE.  To hook into this you simple access it in MXML like so:

<mx:VBox dataChange="do something"/>

With this in mind I suggest that those wishing to do more complex visual changes to their component that {binding} cannot address do the following:

  • create a flag to indicate a data change has occured:
    private var bDataChange:Boolean = false;
  • connect the dataChange hook to the flag:
    <mx:VBox dataChange="bDataChange = true;"/>
  • address the data change in the call to update the display list:
    override protected function updateDisplayList (unscaledWidth:Number, unscaledHeight:Number):void
    {
        super.updateDisplayList(unscaledWidth, unscaledHeight);
        if (bDataChange)
        {
            bDataChange = false;
            //do your custom logic here
         }
    }

The nice bit about this is that you are doing the necessary logic to update the display list when it makes sense to do so (via the already established update framework in the Flex API).  It also reduces the need to override the getter/setter for the data property.



jwolib:Pod – title bar children MXML visibility bug fix
Thursday, April 2, 2009, 8:10 pm
Filed under: actionScript, client side, components, flex, jwo_lib, projects | Tags: , , , , ,

For those of you who use the Pod component I fixed the annoying issue of where title bar children’s visibile properties being set in MXML did not stick.  Anyway revision 122 addresses this issue.

bug detail



jwolib – new release 2008.12.15
Monday, December 15, 2008, 5:25 am
Filed under: actionScript, client side, components, development, flash, flex, jwo_lib, mxml

A user of the lib brought to my attention a major flaw in my default styling setup.  This new release address the default styling as well as a few things regarding the TileCanvas’s itemRenderer (IFactory) generator class (now can use UIComponent, should implement IDataRenderer for best use).

jwolib 2008.12.15 (includes src, asdocs & SWC) – link



as3isolib tutorial added – as3isolib flex integration
Tuesday, November 4, 2008, 5:51 am
Filed under: actionScript, client side, components, development, flex, fun stuff, gaming, isolib, projects, tutorial

The title sums it up – link



as3isolib alpha 2008.11.03 new build released
Monday, November 3, 2008, 11:11 pm
Filed under: actionScript, client side, components, development, flash, fun stuff, gaming, isolib, projects

This release addresses the issues associated with having a large number of scene items that might reside outside of the viewing area.  Also incorporated includeInLayout implementation for IsoContainer objects and renamed a few classes/APIs.

as3isolib home – link
as3isolib 2008.11.03 build – link



Life of a UIComponent
Friday, August 22, 2008, 5:22 pm
Filed under: actionScript, components, development, flash, flex, tutorial

Reality Check

I have been developing in Flash for more years than I can remember and Flex since its inception.  Its amazing how with that many years under my belt, a professional title of “Sr. Flex Consultant” and a pretty good comprehension of the “engine” of AS3, I still don’t know some basic things.

Case in point:

I was browsing Kirupa’s AS3 forums to see if I could swing in and make someone’s day by solving their AS3 woes.  I found a guy who was basically trying to access child DisplayObjects on a DisplayObjectContainer from within the parent’s constructor.  Now I don’t know if he was trying to access children instantiated programmatically or those placed on the timeline (I assume the latter case), but the problem is a result of the child references being null during the constructor.  Seems like an easy solution right?  Just wait and then do a check then any subsequent logic if applicable, else wait some more.

I wanted to provide the guy some insight and so I thought, “you know a UIComponent is pretty damn straight forward”.  It even has a great method called childrenCreated that you can leverage.  But trying to find a solution from a UIComponent is quite difficult because the process isn’t as straight forward as I had assumed it to be.  I was amazed to realize that I hadn’t the clear understanding of what goes on under the hood of the MX framework as I had previously thought.  Anyway, to make a not so long story short, I present a detailed look into the life of a UIComponent.  BTW – all of this material can be found in the API docs as well as snooping around the MX code base.

Life of a UIComponent

Birth

  1. instantiation (aka. the constructor) – so there are a few differences when instantiating programmatically vs. declaritively (via MXML).  For now let’s make the assumption that we are dealing with programmatic instantiation.  The UIComponent doesn’t belong to the displayList, it is simply an object in memory.
  2. configuration – this may happen in the constructor or it may happen immediately after the UIC is created, but most properties needing initialization are set here as well as event handlers and other logic.  Keep in mind that some properties that are actual getters/setters can flag the UIC for invalidation/validation logic.
  3. adding to the displayList – in order to be a useful UIC, it needs to be brought into the fold.  So a parent UIC adds it to its displayList node.  Interestingly, the addng of a UIC to the displayList causes a lot of under-the-hood logic to take place.  For this section, the UIC in question is the one being added, not the parent.
    1. any former parent reference is removed (via DisplayObjectContainer(formerParent).removeChild(this))
    2. the UIC has some initialization performed on it regarding its document properties, styling, and some Module logic with regards to its new position within the displayList.
    3. the UIC is actaully added into the displayList.  This is done at a lower level withing the Flash player.  Doing so triggers an Event.ADDED event which is captured by the UIC’s parent.  This event is delayed and redispatched at a later point.
    4. the UIC’s initialize() method is called which drills down yet another chain of events:
  4. initialization – the UIC’s initialize() method is called which drills down yet another logic chain.  Note the possible recursive nature of this logic:
    1. the FlexEvent.PREINITIALIZE event is dispatched
    2. createChildren() is called
    3. childrenCreated() is called which trigger the invalidateProperties, …Size() and ..DisplayLIst() methods.  Note that the UIC may have been flagged for invalidation in step #2 (the configuration phase)
    4. accesssibilities are initialized
    5. the FlexEvent.INITIALIZE event is dispatched

Life within the display list

Up till now, the life of our UIC has been pretty easy to follow.  It and it’s parent have done quite a bit during the birthing process.  But now that the UIC has been flagged for invalidation, it gets a bit blurry.

  1. invalidation – most of the getters/setters in a UIComponent have some logic that says, “if the new value doesn’t = the old” then it is to invalidate the properties, size and/or displayList.  Most folks who do any component development make a great deal of use of these invalidation methods.  Most folks (like me) probably had assumed their wasn’t any logic that took place betw. invalidation and validation processes.  Oh but there is.An invalidation method is quite simple, it check two things, does the UIC (UIComponent hereinafter) have a parent and has a global-level ILayoutManager exist.  If both conditions are met, then the UIC hands itself over (as a parameter) to the ILayoutManager.   By doing these two checks a Flex app can conserve processing resources in case the UIC doesn’t reside within the displayList.  Why update something that isn’t visible to the user?  It does get updated, it just doesn’t get validated.
  2. managing the layout – Even though the name implies just layout-related tasks, the LayoutManager handles task related to invalidateProperties, invalidateSize and invalidateDisplayList.  By a system of boolean flags and queues, the LayoutManager goes thru the 3 pre-validation phases of telling each UIC in its queue.  Does UIC#2241782 need its size or properties validated?  Does UIC#99892 need to update its display list?  This kind of logic takes place here.  The queing mechanisms are complex and recursive so I won’t go into detail here, but suffice it to say works alot like a short-order cook.

    The really interesting thing about the LayoutManager is that it is main engine that drives the MX framework.  If any of you were ol’ Flash dev’rs and remember having to do onEnterFrame logic, this kind of logic is presented here but in very tricky fashion.  LayoutManager actually has a UIC that doesn’t reside in the display list.   This UIC is called the callLaterObject and as you can guess is used as the work horse for leveraging the ENTER_FRAME and RENDER events that get triggered.  At each triggering, the callLaterObject then reports back to the LayoutManager that we are in the next frame so we can now start the validation process on our queued UICs.

  3. validation – now that we have a new frame to work with, the LayoutManager will goto its needs-validation-queue and grab each UIC and issue validation orders.  Once that is done, the UIC in question gets added to yet another queue and a series of checks takes place before starting all over again for the next round of invalidation requests.

Summary

With the sort of logic that takes place for a mutltitude of UIComponents within an app, the geniuses over at Adobe have come up with a highly efficient system for managing resources while making the updates.  I hope this provides some insight.  And also sound off if you find that I am in error in writing this, as this was a journey of discovery for me as well.

J



Silly Adobe…don’t you know? private means private
Tuesday, July 1, 2008, 12:40 pm
Filed under: actionScript, components, development, flash, flex

Doing component development is a challenging task, especially if you are trying to stick within the guidelines established by the MX framework.  So frustrating is this challenge sometimes, it makes you want to tear clumps of hair from your scalp.

I found this while digging around trying to extend mx:ComboBox:

/**
     *  @private
     */
    private function displayDropdown(show:Boolean, trigger:Event = null):void
    {
        if (!initialized || show == _showingDropdown)
            return;

        // Subclasses may extend to do pre-processing
        // before the dropdown is displayed
        // or override to implement special display behavior

Silly Adobe indeed.



jwolib: Pod gets a much needed update
Wednesday, April 2, 2008, 6:18 pm
Filed under: actionScript, components, development, flex, jwo_lib

Since most people instantiate container type classes via MXML rather than in AS3, it made sense to be able to add title bar components to Pod via MXML rather than the tedious addTitleBarComponent method.

Now if you want to add title bar components to a Pod instance, you can do so declaratively.   Check out titleBarChildren.

You can view an implementation of this here – link



jwolib: new example files and srcview uploaded
Friday, March 28, 2008, 5:54 pm
Filed under: actionScript, components, flex, jwo_lib

project update – link



Flex Drag n’ Drop Lib Docs uploaded
Wednesday, March 26, 2008, 9:15 pm
Filed under: actionScript, components, dNdLib, development, flex

Again, just an update for the dNdLib docs:

dNdLib project home – link
dNdLib docs – link