I typically solve this problem using a TabBar and a ViewStack.  The
ViewStack has all the components and dataProvider for the TabBar is built
according to the permissions, with only the allowed functions.  The
dataProvider items have the index to the corresponding ViewStack child, and
the change event handler sets the ViewStack.selectedIndex with the
item.index value.

 

Tracy Spratt,

Lariat Services, development services available

  _____  

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On
Behalf Of Wesley Acheson
Sent: Wednesday, August 12, 2009 11:06 AM
To: flexcoders
Subject: [flexcoders] TabNavigator changing from MXML to actionscript.

 

  

Hi I've an application already mostly written.

Background:

This application uses several custom components that extend or contain
TabNavigators.

A requrirement which I've missed is that if the user doesn't have permission
to view a tab then the tab doesn't appear in the tab navigators.

However tabs still appear even if the child elements they refer to are
invisible.

So I guess that I need to do something like this in my MXML files.  


<mx:TabNavigator xmlns:mx="http://www.adobe.
<http://www.adobe.com/2006/mxml> com/2006/mxml"
xmlns:component="com.example.test.*" CreationComplete="init()">
...
//Normal stuff in here
...
public var tab1:CustomComponent1;
public var tab2:CustomComponent2;
//etc
...

private function init():void
{
  if (Permissions.hasPermission("viewTab1")
  {
    tab1 = new CustomComponent1;
    ...
    // Set the properties that are normally specified in MXML
    // Add event listeners for all the events normally specified in mxml.
    // e.g. tab1.addEventListener(SaveEvent.SAVE, handleSave);
    // Do any bindings that are normally associated with the MXML
  }
}

...
</mx:TabNavigator>

Questions:

1.      How do I set up the bindings? I have seen http://livedocs.
<http://livedocs.adobe.com/flex/3/html/help.html?content=databinding_7.html>
adobe.com/flex/3/html/help.html?content=databinding_7.html however this
leaves me worried that binding will occur differently.  I'm particually
worried that I'll get binding events occuring before the component is
initialised which won't (As is normal in mxml) be swallowed by the
framework. I don't even know where I'd put a try block for these errors.
2.      Doing things in this way means that tabs the user has permission for
but hasn't clicked on don't apply for deferred instanceiation. Is there any
way to get this back.  (Normally the tab navigator only instances its
children when the appropiate tab is selected).
3.      Creating the child after CreationComplete doesn't feel right to me.
I guess I could overwrite create children in the above example but not when
my MXML file contains a TabNavigator rather than is a TabNavigator which is
also a situation elsewhere in the application. Is there a better way arround
this?  Creating a ChildDiscriptor object. Does doing things in this way mean
a blank component appears then its contents appear?

Thanks in Advance,
Wes








Reply via email to