Ultrashock Forums > Flash > ActionScript
AS3 - Problems with external css

You are currently viewing our website as a guest which gives you limited access to forums, files and other resources.

Click here to join now for free, and start interacting with our members, download files and much more!

Click here if you are looking for our Flash files and other professional assets.
 
Post Reply | View first unread | Rate Thread Search this Thread | Thread Tools | Display Modes

#1
Bookmark and Share!
AS3 - Problems with external css
Old 2008-04-06

Hi,

I'm trying to style a textfield using an external css file. All of the tutorials and previous forum posts I've found seem to suggest the same method, which I think I have followed correctly. However, it doesn't seem to work for some reason.

Actioscript code:

Code:
package {

  import flash.display.Sprite;
  import flash.text.TextField;
  import flash.events.Event;
  import flash.text.TextFieldAutoSize;
  import flash.text.StyleSheet;
  import flash.net.URLLoader;
  import flash.net.URLRequest;

  public class cssText extends Sprite {
	  
    private var loader:URLLoader = new URLLoader(  );
	private var field:TextField = new TextField(  );
      
    public function cssText():void {
         loader.addEventListener(Event.COMPLETE, onLoadCSS);
         var cssFile:URLRequest = new URLRequest("test.css");
         loader.load(cssFile);
    }
    
    private function onLoadCSS(event:Event):void {
      var css:StyleSheet = new StyleSheet();
      css.parseCSS(URLLoader(event.target).data);
	  
         field.autoSize = TextFieldAutoSize.LEFT;
         field.wordWrap = true;
         field.width = 200;
         addChild(field);
         field.styleSheet = css;
		 field.htmlText ="<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec pretium mauris nec justo. Vestibulum tellus. Nulla euismod nibh vitae lorem. Ut ut sapien. Maecenas viverra urna non tellus. Curabitur ultricies lorem quis diam. Sed est lectus, gravida sed, placerat non, sagittis id, leo. Nullam ligula dolor, interdum sit amet, sodales ut, condimentum eu, dui.</p>";
   }
  }
}
CSS:

@charset "utf-8";
/* CSS Document */

p
{
font-size: 24px;
font-family: Arial, Helvetica, sans-serif;
color: #ff0000;
text-align:left;
}

I really hope it's something simple I've overlooked, but I just can't seem to figure it out. Any help would be greatly appreciated.
postbit arrow 1 comment | 682 views postbit arrow Reply: with Quote   
Registered User
rlayte is offline
seperator
Posts: 1
2008-04-05
rlayte lives in United Kingdom
seperator

Ultrashock Member Comments:
delizade delizade is offline 2008-10-22 #2 Old  
first of all, i didnt look at your code but strngly I can tel that DO NOT use
@charset "utf-8";
/* CSS Document */

in your CSS file. it is a problem in As3 parser.
Reply With Quote  
Thread Tools
Display Modes Rate This Thread
Rate This Thread: