Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CSS in flash

Status
Not open for further replies.

blaablaa69

Technical User
Feb 15, 2005
57
AU
Hey,

Im doing a site at the moment which uses an xml file created from a mysql db. I would like to format the text with a external css sheet, from within flash. This is because i want to keep the xml file, strictly content, and format the specific text boxes in flash, with the external css i have already created. Any ideas? and also should i use dynamic text boxes or use the textarea component?
 
Hi. Using CSS in Flash requires the most recent version, ie Flash MX 2004, as far as I know. In MX-04, you'll write something along the lines of:
Code:
var cssStyles:TextField.StyleSheet = new TextField.StyleSheet();
cssStyle.load("youFile.css"); //load the file

//then test that the sheet loaded.
cssStyle.onLoad = function(loaded){
     if(loaded){
        //load the xml file content here (must do this after loading css.
     }
     else{
        trace("Did not load");
     }
};
I think it is something like that. I hope that helps.

URL
 
sorry, I had a small error in my code...here's the fix:
Code:
var cssStyles:TextField.StyleSheet = new TextField.StyleSheet();
cssStyles.load("youFile.css"); //load the file

//then test that the sheet loaded.
cssStyles.onLoad = function(loaded){
     if(loaded){
        //load the xml file content here (must do this after loading css.
     }
     else{
        trace("Did not load");
     }
};
 
thanks for your reply! couple things but. firstly im using an xmlconnector to load my xml and secondly how would i actually apply styles to certain textareas?
 
You enable HTML on your text field. Then you do it the same way you would do it in HTML.

example:

Code:
theHTMLString = "<p class='boldText'>Lorem ipsum dolor sit amet, fringilla vel euismod.</p> Donec litora metus, pretium eos. Sapien pretium, quam libero, est consectetuer justo. Sit varius. Non lectus quam, ultrices in, faucibus vitae. Integer sociosqu tincidunt. Malesuada libero lacus. Nibh sit. Ac dolorem. Et non pede, odio montes, justo dignissim.";

myCSS = new TextField.StyleSheet();
	myCSS.onLoad = function(success) {
		if (success) {
			trace("success");
			textBox.styleSheet = myCSS;
			textBox.htmlText = theHTMLString;
		}
	};
	myCSS.load("style1.css");

Hope that helps.

Wow JT that almost looked like you knew what you were doing!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top