Yet Another GIS Blog
GIS, Geography, Programming, and Neogeography

Flex Label Component Rotation and TextField Rotation

Saturday, 25 April 2009 11:43 by boxshapedwo

I have had some frustrations trying to get a label to rotate 90 degrees in Flex, both as an mxml component and in Actionscript.  The key to this problem has to do with embedding fonts.  The easiest way to embed a font in flex is to use a style component. 


<mx:Style>
@font-face {
src:local("Times New Roman");
fontFamily: myTNR;
advancedAntiAliasing: true;
}
</mx:Style>

The style component is essentially CSS, so you can store the style.  Now when you add a label component to your mxml then you can set the fontFamily property equal to myTNR.

 <mx:Label text="Label" rotation="90" fontFamily="myTNR"/> 

What happens though when you are working with an Actionscript class and not with an mxml file?  In your main mxml file, add the same style component.  In your Actionscript class add a variable before your label variable of the type TextFormat.

var fmt:TextFormat = new TextFormat;
fmt.font = "myTNR"; 
fmt.size = 11; 
//This should be true  if it worked.
trace(Application.application.systemManager.isFontFaceEmbedded(fmt);
var lbl:Label = new TextField; //using a textfield variable
lbl.defaultTextFormat = fmt;
lbl.embedFonts = true;
lbl.text = "some text"; 
lbl.x = 0;
lbl.y = 0; 
//add the textfield as a child to some component 
addChild(lbl);
//then rotate 
lable.rotation = -90;

There are other ways to embed fonts, but I found this to be the easiest way.

Tags:   , ,
Categories:   Neogeography
Actions:   E-mail | del.icio.us | Permalink | Comments (5) | Comment RSSRSS comment feed

Comments

Comments are closed