Solved

AS3 - Can't get style sheet to actually format my text

Posted on 2008-10-19
2
1,307 Views
Last Modified: 2013-11-11
I've got an xml file that allows users of the application I'm creating to enter font/color/size info for a number of styles. I've also got an xmlLoader class that reads in the xml and creates the style sheet. Here's the function in the LoadXML.as class that creates the styles:

private function createTextStyles(_xml) {
                  trace("creating text styles");
                  //create text formats for all font defs
                  fontInfoList = _xml.meta_info.all_swfs.fontFormatInfo.fontFormat;
                  for (var i:int=0; i < fontInfoList.length(); i++)
                        {
                              var styleObj:Object = new Object();
                              trace("fontInfoList[i].font_size: " + fontInfoList[i].font_size);
                              styleObj.fontSize = fontInfoList[i].font_size;
                              trace("styleObj.fontSize: " + styleObj.fontSize);
                              styleObj.color = fontInfoList[i].font_color;
                              styleObj.fontFamily = fontInfoList[i].font_name;
                              var styleName = fontInfoList[i].@fieldType;
                              trace("styleName: " + styleName);
                              fontstyles.setStyle(styleName, styleObj);
                        }
            }
            public function get styleNames():Array
            {
                  return fontstyles.styleNames;
            }


Then in my .fla - I'm creating and text field and applying the appropriate style, as shown here:

function showEmployee(empNum) {
      //projectXML.formatEmployeeText(i);
      trace("calling emp info");
      var empInfo = projectXML.getEmployeeInfo(empNum);
      //projectXML.getEmployeeInfo(empNum);
      var tf:TextField = new TextField();
      tf.x = 25;
      tf.y = 25;
      tf.width = 500;
      tf.multiline = true;
      tf.wordWrap = true;
      tf.autoSize = TextFieldAutoSize.LEFT;
      tf.styleSheet = projectXML.getStyleSheet();
      tf.htmlText = "<span class='nameheading'>" + empInfo.empname + "</span>";
      addChild(tf);
      
}

The problem is that the style 'nameheading' is not applied. My text displays in tiny Times Roman. I'm sure I'm doing something simple incorrectly, but when I look at the documentation, I seem to be doing everything correctly. Can anyone point me to my error?
0
Comment
Question by:katyjack
2 Comments
 
LVL 39

Accepted Solution

by:
blue-genie earned 500 total points
ID: 22756547
what format does your nameheading output in?

should be something along these lines?

  .nameheading {
      blah blah
   }
0
 

Author Closing Comment

by:katyjack
ID: 31507594
That was it - I didn't have the . in front of the name.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question