OK, in my quest for reusable shell (
http://tech.groups.yahoo.com/group/flexcoders/message/76641 ) I am now
pretty close to what I would like to achieve. I've created template
component (
http://livedocs.adobe.com/flex/201/html/templating_150_2.html ) which
expects ViewStack component in its 'pages' property. Component looks
something like this:

Shell.mxml:
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml";>
  
  <mx:Image /><!-- company logo -->
  <my:Footer />
  <!-- etc. -->
        
  <mx:Script>
    ...
    public var pages : ViewStack;
    private function init() : void {
      addChild(pages);
    }
    ...
  </mx:Script>
        
</mx:Canvas>

This allows me to design the shell visually. One goal achieved.

In the application, I can now use something like:

<my:Shell>
<my:pages>
<mx:ViewStack>
...
<mx:ViewStack>
<my:pages>
</my:Shell>

This is ideal ... except ... Flex Builder unfortunately does not
support this in design view (it won't display content of my:pages tag).

This lead me to this first workaround: with one line of code, I was
able to create my:Shell, create mx:ViewStack somewhere outside the
shell and then, in initialize event handler, I moved the mx:ViewStack
to be a child of myShell.pages property.

In the design view, I was then able to design content of mx:ViewStack
but it appears outside of my:Shell component. Although I guess I could
use absolute positioning to make the ViewStack appear above the shell
and simulate the final look and feel, this is still not perfect.

So I tried another trick - simply create the MXML this way:

<my:Shell>
<mx:ViewStack>
...
<mx:ViewStack>
</my:Shell>

Note that the ViewStack isn't nested inside my:pages property. Flex
designer now happily displays ViewStack inside the my:Shell area so
from the designer perspective, we are now done: both shell and client
application can be designed visually.

But - and this is a big "but" - it won't run because "Multiple sets of
visual children have been specified for this component". Obviously -
the Shell component defines some child elements in MXML so syntax in
in the client app is incorrect. But don't worry, I was telling myself,
a few lines of code will fix it. All I need in this situation is to
move the mx:ViewStack from my:Shell to myShell.pages property - sounds
very simple but in practice, all my attempts failed.
creationPolicy="none" doesn't work for me (I don't know why) and when
I try to move the ViewStack in initialize event handler, it's too late
(the Exception has already be thrown). On the other hand, preinit is
too early as the shell isn't initialized yet.

I need an advice here - I thinks that it should be doable somehow but
I can't figure it out.

It's been a long journey and I don't want to fail right before the end :)

Thanks,
Borek

Reply via email to