How to access loaded StyleSheet from master (main) swf using Flash AS3

I have a class CSSLoader that loads css data into a stylesheet, '_flashStyles'.  This works as planned.  I have a master swf that controls a site.  Master instantiates a new CSSLoader and loads the external css.  This also works. Various pages are loaded into the master swf when called by the site navigation.  These pages have text to be styled by the  loaded stylesheet, but I'm unable to apply the stylesheet to the text.  I've tried approaches like 'myText.styleSheet = CSSLoader._flashStyles without success.  can any body point me in the right direction?  This is an AS3 question.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

have you got got styles working before, incase you didnt know this but it has to be done in the correct order and you must use htmlText instead:

var label:TextField = new TextField();
label.styleSheet = CSSLoader._flashStyles;
label.htmlText = "<h1>header eg</h1>";

not sure how you are defining _flashStyles, i would use something like:
    import flash.text.StyleSheet;
    public class CSSLoader
        public static var _flashStyles:StyleSheet = StyleSheetMaker('link');
       public static function StyleSheetMaker ()
dlearman1Author Commented:
Thanks for your comment.  I have attached the related code.  Sorry about throwing so much code at ypu, but I didn't see a way to shorten it.

The basic idea is to have a reusable Class CSSLoader located in an directory outside the current project directory (com.pricelearman.loaders).  Individual projects (websites) would than have a Master (Main) Class which would instantiate CSSLoader to load the css files for that particular project.

Where I am now:  Master can instantiate CSSLoader and successfully load the css data from an external file (_css/flashStyles).  My problem is once loaded I cannot see how to access the loaded stylesheet for use within Master or within additional SWF's that might be loaded into Master.

What I'm trying to do is build a framework for creating a single frame, full-Flash website.

// Class to load CSS
package com.pricelearman.loaders {
	import flash.text.StyleSheet;
	import flash.system.LoaderContext;
	import flash.system.ApplicationDomain;
	import flash.display.Loader
	public class CSSLoader extends EventDispatcher {
		public var loadFrom:String;
		public static const CSSLOAD_COMPLETE:String = "CSSLoadComplete";
		public var _loadFrom:String;
		public var _isVerbose:Boolean;
		public var _flashStyles:StyleSheet;
		public var _cssInfo:URLLoader;
		// Constructor
		public function CSSLoader() {
		}	// End Constructor
		public function createURLLoader():void {
			trace("createURLLoader has launched");
			_cssInfo = new URLLoader();
			_cssInfo.dataFormat = URLLoaderDataFormat.TEXT;
			_cssInfo.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
			_cssInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true);
		}	// end createURLLoader
		public function loadCSS(loadFrom:String):void {
			_loadFrom = loadFrom = "_css/flashStyles.css";
			trace("loadCSS at has launched");
			try {_cssInfo.load(new URLRequest(loadFrom)) } 
				catch (err:Error) {
				trace("Unable to load content:\n"+err.message);
		}	// end loadCSS
		public function onComplete(evt:Event):StyleSheet {
			trace("onComplete has launched");
			_flashStyles = new StyleSheet();
			trace("Styles loaded = "+_flashStyles.styleNames);
			_cssInfo.removeEventListener(Event.COMPLETE, onComplete);
			_cssInfo.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);
			return _flashStyles;
			dispatchEvent(new Event(_cssInfo.CSSLOAD_COMPLETE));
		}	// end onComplete
		private function onIOError(evt:IOErrorEvent):void {
			trace("onIOError has launched");
			trace("A loading error has occurred:\n", evt.text);
		}	// end onIOError
	}	// end CSSLoader
}	// End Package
// Master (Main) class for website application.  Instantiates CSSLoader //and attempts to use the stylesheet.  
package protoSite {
	import flash.display.*;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.system.LoaderContext;
	import flash.system.ApplicationDomain;
	import flash.geom.Point;
	import flash.text.*;
	import flash.text.TextField;
	import flash.text.StyleSheet;
	import com.pricelearman.loaders.FontLoader;
	import com.pricelearman.loaders.CSSLoader;
	import com.pricelearman.core.TraceDisplayList;
	import com.pricelearman.loaders.DisplayLoader;
	public class Master extends MovieClip {
		//public var cssLoader:CSSLoader;
		public var flashStyles:StyleSheet;
		public var _displayLoader:DisplayLoader;
		public var loadedPage:Sprite;
		//public var fontSource:String = "embeddedFonts.swf";
		//public static const FONTLOAD_COMPLETE:String = "fontLoadComplete";
		private var _wrapper:Sprite;
		private var _progressHolder:Sprite;
		private var _footer:Sprite;
		private var _header:Sprite;
		private var _page:Sprite;
		private var _navigation:Sprite;
		private var _dispObj:*;
		private var _indentLevel:Number;
		private var _thisStageWidth:Number = 950;
		private var _thisStageHeight:Number = 525;
		private var _progressDisplay:Sprite;
		private var _progressText:TextField;
		private var _loadedAsset:*;
		private var _testText:TextField;
		private var _testFormat:TextFormat;
		private var _fontLoader:FontLoader;
		private var _cssLoader:CSSLoader;
		//private var _context:LoaderContext;
		//private var _fontLoader:Loader
		//private var _fontURL:URLRequest;
		private var _fontSource:String;
		public function Master(fontSource:String='embeddedFonts.swf') {
			trace("Master Class Instantiated");
			_fontSource = fontSource;
		}	// End Constructor
		private function verifyChildren():void {
			trace("Number of Children of Stage = "+stage.numChildren);
			trace("Child of Stage is: "+stage.getChildAt(0));
			trace("stage refers to: "+stage);
			trace("this refers to: "+this);
			trace("root refers to: "+root);
			// only one child allowed in Document Class root
			if (stage.numChildren > 1) {
				throw (new Error("Document Class is allowed only one child instance"));
			} else {
				trace("Master Class is active");
		}	// End verifyChildren
		private function init():void {
			trace("init launched");
			_wrapper = new Sprite();
			_wrapper.x = 0;
			_wrapper.y = 0;
			trace("wrapper xPos = "+_wrapper.x);
			trace("wrapper yPos = "+_wrapper.y);
			_footer = new Sprite();
			_footer.x = 0;
			_footer.y = 600;
			trace("footer xPos = "+_footer.x);
			trace("footer yPos = "+_footer.y);
			_header = new Sprite();
			_header.x = 0;
			_header.y = 0;
			trace("header xPos = "+_header.x);
			trace("header yPos = "+_header.y);
			_page = new Sprite();
			_page.x = 0;
			_page.y = 130;
			trace("page xPos = "+_page.x);
			trace("page yPos = "+_page.y);
			_navigation = new Sprite();
			_navigation.x = 0;
			_navigation.y = 80;
			trace("nav xPos = "+_navigation.x);
			trace("nav yPos = "+_navigation.y);
			traceChildren(this.stage, 0);
		}	// End init
		private function doLoadFonts(fontSource:String):void {
			trace("loadFonts launched");
			_fontSource = fontSource;
			_fontLoader = new FontLoader(_fontSource);
			_fontLoader.addEventListener(FontLoader.FONTLOAD_COMPLETE, onFontLoadComplete);
		}	// end doLoadFonts
		public function onFontLoadComplete(evt:Event):void {
			trace(">>>>> onFontsComplete launched");
		}	// end onComplete
		private function doLoadCSS():void {
			trace(">>>>> onLoadCSS launched");
			_cssLoader = new CSSLoader();
			_cssLoader.addEventListener(CSSLoader.CSSLOAD_COMPLETE, onCSSComplete);
		}	// end loadCSS
		public function onCSSComplete(evt:Event):void {
			trace(">>>>> onCSSComplete launched");
		}	// end onComplete
		function showDisplayList():void {
		var displayList:TraceDisplayList = new TraceDisplayList();
		displayList.showChildren(stage, 0);
		}	// end showDisolayList
		private function padIndent(indents:int):String {
			var indent:String = "";
			for (var i:uint = 0; i < indents; i++) {
				indent += "    ";
			return indent;
		public function traceChildren(dispObj:*, indentLevel:Number):void {
			_dispObj = dispObj;
			_indentLevel = indentLevel;
			for (var i:uint = 0; i < _dispObj.numChildren; i++) {
				var obj:DisplayObject = _dispObj.getChildAt(i);
				if (obj is DisplayObjectContainer) {
					trace(padIndent(_indentLevel),, obj);
					traceChildren(obj, _indentLevel + 1);
				} else {
					trace(padIndent(_indentLevel) + obj);
		public function doLoadPage():void {
			trace("doLoadPage has Launched");
			//_displayLoader = new DisplayLoader("", _wrapper, new Point(385, 50), 0, true, true);
			_displayLoader = new DisplayLoader("home.swf", _wrapper, new Point(0, 0), 0, true, true);
			//_displayLoader.addEventListener("displayObjectLoaded", onLoadDisplayComplete, false, 0, true);
			_progressDisplay = _displayLoader.progressDisplay;
			var _progressText:TextField = _displayLoader.progressText;
		}	// end doLoadDisplay
		private function onLoadDisplayComplete(evt:Event):void {
			trace("Remove Child Launched");
			_loadedAsset = _displayLoader.asset;
		// ************************************************************************************************
		// Test for embedded fonts
		// Comment out this code prior to final compile
		// ************************************************************************************************
		private function doFontTest():void {
			trace(">>>>> doFontTest Launched");
			_testFormat = new TextFormat();
			_testFormat.font = getFont("Sloop-ScriptOne");
			trace(">>>>> _testFormat.font = "+_testFormat.font);
			_testFormat.size = 48;
			_testFormat.color = 0x00FF00;
			_testText = new TextField();
			_testText.x = 100;
			_testText.y = 100;
			_testText.width = 400;
			_testText.height = 200;
			_testText.multiline = true;
			_testText.embedFonts = true;
			_testText.rotation = 45;
			//_testText.styleSheet = _cssLoader._flashStyles;
			_testText.text = "<span class='head'>If the font is embeded</span><span class='body'> this text will be rotated 45 degrees</span>";
		}	// end doFontTest
	}	// End Master Class
}	// End Package

Open in new window

Sorry i cannt but much more help but im under a lot of stress and getting my head around this much code isnt going to happen. Good luck fixing this.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.