// we have to init the minimap after the content is loaded for both // the minimap and the scroll pane so remember who's loaded var minimapContentLoaded:Boolean = false; var scrollPaneContentLoaded:Boolean = false; // setup the minimap event listener var minimapListener:Object = new Object(); minimapListener.complete = function(evt:Object):Void { minimapContentLoaded = true; if (scrollPaneContentLoaded) { // both the minimap and the scroll pane are loaded initMinimap(); } }; minimapListener.change = function(evt:Object):Void { // the minimap changed, update the scroll pane scrollPane.hPosition = minimap.getHighlightFractionX() * scrollPane.maxHPosition; scrollPane.vPosition = minimap.getHighlightFractionY() * scrollPane.maxVPosition; }; minimap.addEventListener("complete", minimapListener); minimap.addEventListener("change", minimapListener); // setup the scroll pane event listener var scrollPaneListener:Object = new Object(); scrollPaneListener.complete = function(evt:Object):Void { scrollPaneContentLoaded = true; if (minimapContentLoaded) { // both the minimap and the scroll pane are loaded initMinimap(); } }; scrollPaneListener.scroll = function(evt:Object):Void { // the scroll pane moved, update the mini map minimap.setHighlightFractionX(scrollPane.hPosition / scrollPane.maxHPosition); minimap.setHighlightFractionY(scrollPane.vPosition / scrollPane.maxVPosition); }; scrollPane.addEventListener("complete", scrollPaneListener); scrollPane.addEventListener("scroll", scrollPaneListener); function initMinimap():Void { // the only initialization is minimap.setHighlightFractionSize( scrollPane.width / scrollPane.maxHPosition, scrollPane.height / scrollPane.maxVPosition); }