Im trying to create a function that will displays fractions in a textfield in the correct format, because 1/4 or 1/2 isnt being accepted by e-learning people as the correct way to display a fraction. So to do this dynamically, i just thought about creating a 3 line dynamic textfield on the fly, placing the numerator of the fraction on the first line, a dash on the second line and the denominator on the third line and then changing the lineSpacing of the textfield to squeeze it all together vertically, but of course, this is the only property of the TextFormat object that is missing and thus cannot be set dynamically, nor can you pass a negative integer as a value for the TextFormat.leading property unless you specify it using the leading attribute of the textformat html node and pass it to the htmlText property of a textfield(Thanks to Peter Hall)....
So ive created a movieclip method that will display a fraction correctly for you. This function creates one container movieclip, which inside contains two textfields and one movieclip, the first textfield contains the numerator, the second textfield contains the denominator and the movieclip contains a line between the numerator and the denominator drawn using the drawing api.
| MovieClip.prototype.createFractionField=function(name,depth,x,y,numerator,denominator,lineSpacing)
{ var cnt=this.createEmptyMovieClip(name,depth,{_x:x,_y:y}) cnt.createTextField("numerator",1,0,0,0,0) var numeratorF=cnt.numerator var dash=cnt.createEmptyMovieClip("dash",2) cnt.createTextField("denominator",3,0,0,0,0) var denominatorF=cnt.denominator numeratorF.autoSize=denominatorF.autoSize=true numeratorF.text=numerator denominatorF.text=denominator var nw=numeratorF._width var dw=denominatorF._width var gw=(nw>=dw) ? nw : dw var hw=gw/2 numeratorF._x=hw-(nw/2) denominatorF._x=hw-(dw/2) dash.lineStyle(0,0x000000) dash.lineTo(gw,0) dash._y=numeratorF._height+lineSpacing denominatorF._y=dash._y+dash._height+lineSpacing } |
And you use it like this:
| //display 1/10 correctly as a fraction for me
this.createFractionField("myFraction",1,0,0,1,10,2) |


