ironchefmoto
06-19-2008, 02:40 PM
I have a Shell.as class set to my project's document class. In Shell.as, I instantiate one instance each of Background.as and Navigation.as. Background.as uses BulkLoader to load all the project's background images and what not. When it's done, it dispatches a custom event up to Shell.as:
private function onAllComplete(e:Event):void
{
trace(":: Background.onAllComplete() ::");
// instantiate content background sprite
_bgContent = new Sprite();
// position the content background sprite
_bgContent.x = BG_CONTENT_X;
_bgContent.y = BG_CONTENT_Y;
// draw content background sprite
with (_bgContent)
{
graphics.beginFill(BG_CONTENT_COLOR);
graphics.drawRect(0, 0, BG_CONTENT_WIDTH, BG_CONTENT_HEIGHT);
graphics.endFill();
}
// get background bitmap
_bgBitmap = e.target.getBitmap("background");
// get team logo bitmap
_teamLogoBitmap = e.target.getBitmap("team_logo");
_teamLogoBitmap.x += BG_MARGIN_X;
// get market logo bitmap
_marketLogoBitmap = e.target.getBitmap("market_logo");
_marketLogoBitmap.x = BG_WIDTH - _marketLogoBitmap.width - BG_MARGIN_X;
_marketLogoBitmap.y += BG_MARGIN_Y;
// set instance names
_bgContent.name = "background_content";
// add children to display list
addChild(_bgBitmap);
addChild(_teamLogoBitmap);
addChild(_marketLogoBitmap);
addChild(_bgContent);
// dispatch BG_COMPLETE event to Shell.as; set bubbling to true
dispatchEvent(new Event(BG_COMPLETE, true));
// remove BulkLoader event listeners
bgLoader.removeEventListener(BulkLoader.COMPLETE, onAllComplete);
bgLoader.removeEventListener(BulkLoader.PROGRESS, onAllProgress);
}
Navigation.as does the same thing -- but it's not loading a bunch of things. I just want to be notified when it's done. Probably instantly, since it's just using the drawing methods in Flash 9:
private function renderNav():void
{
trace(":: Navigation.renderNav() ::");
var nav_tab:NavTab;
var nav_shift:Number = 0;
_navItems = new Array();
for (var i:uint = 0; i < TAB_ACTION.length; i++)
{
// create new instance of tab graphic sprite
nav_tab = new NavTab(
_tabLabels[i].toUpperCase(),
_actColorTop,
_actColorBottom,
_inactColorTop,
_inactColorBottom);
// give each instance an incremental instance name
nav_tab.name = "nav_tab_" + i;
// shift each new instance to the right to create overlapping tabs
nav_tab.x += nav_shift;
// incremement the cumulative x shift until you reach the last tab
if (i < TAB_ACTION.length)
{
nav_shift += TAB_SPACING_X;
}
// set the sprite button mode to true
nav_tab.buttonMode = true;
nav_tab.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
nav_tab.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
nav_tab.addEventListener(MouseEvent.CLICK, onMouseClick);
// add each sprite button to the navigation items array for easy reference
_navItems.push(nav_tab);
// add the tab instance to the display list
addChild(nav_tab);
}
// dispatch NAV_COMPLETE event to Shell.as; set bubbling to true
dispatchEvent(new Event(NAV_COMPLETE, true));
}
Background.as dispatches fine. But Navigation never gets received by Shell.as. No errors. Nothing. Here are the event handlers from Shell.as:
addEventListener("onNavComplete", onNavComplete);
addEventListener("onBackgroundComplete", onBackgroundComplete);
// event handler - "onNavComplete" custom event
private function onNavComplete(e:Event):void
{
trace(":: Shell.onNavComplete() ::");
// make _navigation visible when it is complete
_navigation.visible = true;
}
// event handler - "onBackgroundComplete" custom event
private function onBackgroundComplete(e:Event):void
{
trace(":: Shell.onBackgroundComplete() ::");
// make _background visible when it is complete
_background.visible = true;
}
Any ideas why I can't make the Navigation.as dispatchEvent work? Is it just being processed too fast?
IronChefMorimoto
private function onAllComplete(e:Event):void
{
trace(":: Background.onAllComplete() ::");
// instantiate content background sprite
_bgContent = new Sprite();
// position the content background sprite
_bgContent.x = BG_CONTENT_X;
_bgContent.y = BG_CONTENT_Y;
// draw content background sprite
with (_bgContent)
{
graphics.beginFill(BG_CONTENT_COLOR);
graphics.drawRect(0, 0, BG_CONTENT_WIDTH, BG_CONTENT_HEIGHT);
graphics.endFill();
}
// get background bitmap
_bgBitmap = e.target.getBitmap("background");
// get team logo bitmap
_teamLogoBitmap = e.target.getBitmap("team_logo");
_teamLogoBitmap.x += BG_MARGIN_X;
// get market logo bitmap
_marketLogoBitmap = e.target.getBitmap("market_logo");
_marketLogoBitmap.x = BG_WIDTH - _marketLogoBitmap.width - BG_MARGIN_X;
_marketLogoBitmap.y += BG_MARGIN_Y;
// set instance names
_bgContent.name = "background_content";
// add children to display list
addChild(_bgBitmap);
addChild(_teamLogoBitmap);
addChild(_marketLogoBitmap);
addChild(_bgContent);
// dispatch BG_COMPLETE event to Shell.as; set bubbling to true
dispatchEvent(new Event(BG_COMPLETE, true));
// remove BulkLoader event listeners
bgLoader.removeEventListener(BulkLoader.COMPLETE, onAllComplete);
bgLoader.removeEventListener(BulkLoader.PROGRESS, onAllProgress);
}
Navigation.as does the same thing -- but it's not loading a bunch of things. I just want to be notified when it's done. Probably instantly, since it's just using the drawing methods in Flash 9:
private function renderNav():void
{
trace(":: Navigation.renderNav() ::");
var nav_tab:NavTab;
var nav_shift:Number = 0;
_navItems = new Array();
for (var i:uint = 0; i < TAB_ACTION.length; i++)
{
// create new instance of tab graphic sprite
nav_tab = new NavTab(
_tabLabels[i].toUpperCase(),
_actColorTop,
_actColorBottom,
_inactColorTop,
_inactColorBottom);
// give each instance an incremental instance name
nav_tab.name = "nav_tab_" + i;
// shift each new instance to the right to create overlapping tabs
nav_tab.x += nav_shift;
// incremement the cumulative x shift until you reach the last tab
if (i < TAB_ACTION.length)
{
nav_shift += TAB_SPACING_X;
}
// set the sprite button mode to true
nav_tab.buttonMode = true;
nav_tab.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
nav_tab.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
nav_tab.addEventListener(MouseEvent.CLICK, onMouseClick);
// add each sprite button to the navigation items array for easy reference
_navItems.push(nav_tab);
// add the tab instance to the display list
addChild(nav_tab);
}
// dispatch NAV_COMPLETE event to Shell.as; set bubbling to true
dispatchEvent(new Event(NAV_COMPLETE, true));
}
Background.as dispatches fine. But Navigation never gets received by Shell.as. No errors. Nothing. Here are the event handlers from Shell.as:
addEventListener("onNavComplete", onNavComplete);
addEventListener("onBackgroundComplete", onBackgroundComplete);
// event handler - "onNavComplete" custom event
private function onNavComplete(e:Event):void
{
trace(":: Shell.onNavComplete() ::");
// make _navigation visible when it is complete
_navigation.visible = true;
}
// event handler - "onBackgroundComplete" custom event
private function onBackgroundComplete(e:Event):void
{
trace(":: Shell.onBackgroundComplete() ::");
// make _background visible when it is complete
_background.visible = true;
}
Any ideas why I can't make the Navigation.as dispatchEvent work? Is it just being processed too fast?
IronChefMorimoto