# Xml loaded after my scorllBar class has it's values for the content height

**URL:** <https://forum.kirupa.com/t/xml-loaded-after-my-scorllbar-class-has-its-values-for-the-content-height/313418>\
**Category:** Uncategorized\
**Created:** [August 29, 2010, 5:07pm UTC](https://forum.kirupa.com/t/xml-loaded-after-my-scorllbar-class-has-its-values-for-the-content-height/313418 "2010-08-29T17:07:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![icekomo](https://avatars.discourse-cdn.com/v4/letter/i/bcef8e/32.png) [@icekomo](https://forum.kirupa.com/u/icekomo)\
**Post date:** [August 29, 2010, 5:07pm UTC](https://forum.kirupa.com/t/xml-loaded-after-my-scorllbar-class-has-its-values-for-the-content-height/313418/1 "2010-08-29T17:07:07Z")

</div>

I am loading xml into a dynamic textfield. I have a scroll bar class that controls the scrolling of the dynamic text field. The problem I am having is the scrollbar class is getting its height and length values before the xml is loaded, so not all the content scrolls because of this. Is there a way I can get my xml to load first before the scrollbar class looks for those values?

Here is my code:

Loading xml is in my main .as file

//---------------------------------------------css

var cssReq:URLRequest = new URLRequest(“xml/styles/styles.css”);

var cssLoader:URLLoader = new URLLoader();  
cssLoader.addEventListener(Event.COMPLETE, onCSSFileLoaded);  
cssLoader.load(cssReq);  
var sheet:StyleSheet = new StyleSheet();

function onCSSFileLoaded(event:Event):void  
{

```
sheet.parseCSS(cssLoader.data);
PC.menuMc.menuSections.brunch.brunchMenu.content_mc.menuTxt.styleSheet = sheet;

```

}

//---------------------------------------------------Load in XML  
var data\_xml:XML = new XML();  
var xmlReq:URLRequest = new URLRequest(“xml/Menus.xml”);  
var xmlLoader:URLLoader = new URLLoader();  
data\_xml.ignoreWhitespace = true;

function xmlLoaded(event:Event):void  
{  
//brunch  
data\_xml = new XML(event.target.data);  
trace(event.target.data);  
PC.menuMc.menuSections.brunch.brunchMenu.content\_mc.menuTxt.htmlText = String(data\_xml.Brunch).replace("  
", “”);  
}

// adds listener to load XML  
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);  
xmlLoader.load(xmlReq);

Here is my scroll bar class:  
package com.scrollBar  
{  
import flash.display.MovieClip;  
import flash.events.MouseEvent;  
import flash.geom.Rectangle;  
import flash.display.Stage;  
import flash.events.Event;  
import flash.text.\*;

```
public class ScrollBars extends MovieClip
{
	public var scrollbarHeight:Number = 0;
	public var contentHeight:Number = 0;
	public var scrollDraggerHeight:Number = 0;
	public var maskHeight:Number = 0;
	public var scrollAmout:Number = 0;
	public var topBound:Number = 0;
	public var bottomBound:Number = 0;	
	public var startPos:Number = 0;
	public var leftBound:Number = 0;
	public var absNumSet:Number = 0;
	
public function ScrollBars()
	{
		scrollbarHeight = bar_mc.height;
		contentHeight = content_mc.height;
		//contentHeight = content_mc.menuTxt.textHeight;
		//trace(content_mc.reviewsTxt.textHeight);
		//content_mc.reviewsTxt.addEventListener(Event.CHANGE,onTextChange,false,0,true);
		content_mc.menuTxt.autoSize = TextFieldAutoSize.LEFT;
		contentHeight = content_mc.menuTxt.htmlText.length;
		trace(content_mc.menuTxt.htmlText.length);
		trace(content_mc.height);
		scrollDraggerHeight = drag_mc.height;
		maskHeight = contentMask.height;
		scrollAmout = (contentHeight-maskHeight)/(scrollbarHeight-scrollDraggerHeight);
		topBound = bar_mc.y;
		bottomBound = bar_mc.height-scrollDraggerHeight+bar_mc.y + 5;
		startPos = content_mc.y;
		leftBound = bar_mc.x
		drag_mc.buttonMode = true;
		
		content_mc.cacheAsBitmap = true;
		// Event Listeners
		drag_mc.addEventListener(MouseEvent.MOUSE_DOWN, scrollDraggerPress);
		//-------------------------------------------------------------------------------needs looked at used to have the word stage here
		
	}
	public function scrollDraggerPress(event:MouseEvent):void 
	{ 
   		 // Set bounds using some of the scroller BG properties claimed above
		var bounds:Rectangle = new Rectangle(leftBound, topBound, 0, bottomBound);
		drag_mc.startDrag(false, bounds);
		stage.addEventListener(MouseEvent.MOUSE_MOVE, reportStageMouse);
		stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpOnStage);
	}
	public function reportStageMouse(event:MouseEvent):void 
	{
		absNumSet = Math.abs(bar_mc.y - drag_mc.y);
		content_mc.y = Math.round(absNumSet * - 1 * scrollAmout + startPos);
	}
		// When mouse is released while dragging we do this
	public function mouseUpOnStage(event:MouseEvent):void 
	{ 
		drag_mc.stopDrag();
		stage.removeEventListener(MouseEvent.MOUSE_MOVE, reportStageMouse);
		stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUpOnStage);
	}
}

```

}

Thanks for the help in advance!
