15.10.2012 Views

Actionscript 3 Entwicklerhandbuch

Actionscript 3 Entwicklerhandbuch

Actionscript 3 Entwicklerhandbuch

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.

ACTIONSCRIPT 3.0 ENTWICKLERHANDBUCH<br />

Verwenden der Flash Text Engine<br />

}<br />

}<br />

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

{<br />

if (size > 5)<br />

{<br />

var ef2:ElementFormat = ef1.clone();<br />

ef2.fontSize = size;<br />

te.elementFormat = ef2;<br />

this.rebreakLines();<br />

}<br />

}<br />

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

{<br />

var ef2:ElementFormat = ef1.clone();<br />

ef2.typographicCase = newCase;<br />

te.elementFormat = ef2;<br />

}<br />

HeadlineTextBlock.as erweitert die FormattedTextBlock-Klasse und wird zur Erstellung von Schlagzeilen verwendet.<br />

Es enthält eine Funktion zur Einpassung von Text in einen vorgeschriebenen Rahmen auf der Seite.<br />

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

{<br />

import flash.text.engine.*;<br />

public class HeadlineTextField extends 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:ElementFormat,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.length;<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 />

Letzte Aktualisierung 27.6.2012<br />

448

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

Saved successfully!

Ooh no, something went wrong!