I’m building a little widget that has 3-tab navigation. I’ve written the following classes (small subset, anyway) to control everything:
[LIST]
[]Shell.as - the document class, responds to navigation class and loads tab content classes as needed
[]Navigation.as - extends Sprite; receives parameters for tab colors/labels from Shell.as (unrelated XML call for configuration) and generates 3 tabs using a NavTab.as (extends Sprite) class for the button graphics; dispatches CLICK event back to Shell.as for content load handling
[*]GameDayTab.as / TeamInfoTab.as / NewsTab.as - all extend Sprite; each loads various XML feeds and graphics depending on function to render the “content” of each tab; instantiated from Shell.as and, ideally, removed by Shell.as when Shell.as gets calls from Navigation.as
[/LIST]
This is the event I’m dispatching from Navigation.as back to Shell.as to handle tab content loading:
public function onMouseClick(e:Event):void
{
trace(":: onClick() ::");
currentTab = e.currentTarget.name;
trace(":: onClick() : currentTab : " + currentTab + " ::");
dispatchEvent(new Event(NAV_CLICK, true));
}
Shell.as receives this event and processes it with this rather pair of functions:
private function onNavClick(e:Event):void
{
trace(":: onNavClick() ::");
loadTab(_navigation.currentTab);
}
// load tab
private function loadTab(tab_type:String):void
{
trace(":: loadTab() ::");
switch(tab_type)
{
case "nav_tab_0" :
_gameDayTab = new GameDayTab(_configData.game_day_tab_xml, _cssStyles);
addChild(_gameDayTab);
break;
case "nav_tab_1" :
_teamInfoTab = new TeamInfoTab(_configData.team_info_tab_xml, _cssStyles);
addChild(_teamInfoTab);
break;
case "nav_tab_2" :
_newsTab = new NewsTab(_configData.news_tab_xml, _cssStyles);
addChild(_newsTab);
break;
}
}
I need to be a little more elaborate with this code, I know, but i guess what I’m trying to figure out is how to REMOVE a tab content class from the stage. I tried removeChild(), which didn’t work – I understand that’s only removing the reference to that object now, and I really also need to clean up what each tab content instance loads (BulkLoader, other sprites, textfields, etc.).
Not ideal to reload the entire tab content instance each time, but I just wanna make sure that I know the basics of what I’m trying to achieve.
Any assistance is greatly appreciated.
Regards,
IronChefMorimoto