13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Using the Flash Text Engine<br />

}<br />

}<br />

public function changeSize(size:uint=12):void<br />

{<br />

if (size > 5)<br />

{<br />

var ef2:Elem<strong>en</strong>tFormat = ef1.clone();<br />

ef2.fontSize = size;<br />

te.elem<strong>en</strong>tFormat = ef2;<br />

this.rebreakLines();<br />

}<br />

}<br />

public function changeCase(newCase:String = "default"):void<br />

{<br />

var ef2:Elem<strong>en</strong>tFormat = ef1.clone();<br />

ef2.typographicCase = newCase;<br />

te.elem<strong>en</strong>tFormat = ef2;<br />

}<br />

HeadlineTextBlock.as ext<strong>en</strong>ds the FormattedTextBlock class and is used for creating headlines. It includes a function<br />

for fitting text within a defined space on the page.<br />

package com.example.programmingas3.newslayout<br />

{<br />

import flash.text.<strong>en</strong>gine.*;<br />

public class HeadlineTextField ext<strong>en</strong>ds FormattedTextBlock<br />

{<br />

public static var MIN_POINT_SIZE:uint = 6;<br />

public static var MAX_POINT_SIZE:uint = 128;<br />

public function HeadlineTextField(te:Elem<strong>en</strong>tFormat,txt:String,colW:int = 0)<br />

{<br />

super(te,txt);<br />

}<br />

public function fitText(maxLines:uint = 1, targetWidth:Number = -1):uint<br />

{<br />

if (targetWidth == -1)<br />

{<br />

targetWidth = this.width;<br />

}<br />

var pixelsPerChar:Number = targetWidth / this.blockText.l<strong>en</strong>gth;<br />

var pointSize:Number = Math.min(MAX_POINT_SIZE,<br />

Math.round(pixelsPerChar * 1.8 * maxLines));<br />

if (pointSize < 6)<br />

{<br />

// the point size is too small<br />

return pointSize;<br />

}<br />

this.changeSize(pointSize);<br />

if (this.totalTextLines > maxLines)<br />

Last updated 6/6/2012<br />

422

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!