Solved

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

Posted on 2008-10-19
2
1,289 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now