Created
August 26, 2011 21:49
-
-
Save kristoferjoseph/1174512 to your computer and use it in GitHub Desktop.
It's SO easy to style a hyperlink in Flex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package flashx.textLayout.elements.examples { | |
import flash.display.Sprite; | |
import flash.text.engine.FontPosture; | |
import flash.text.engine.Kerning; | |
import flashx.textLayout.container.ContainerController; | |
import flashx.textLayout.edit.SelectionFormat; | |
import flashx.textLayout.edit.SelectionManager; | |
import flashx.textLayout.elements.Configuration; | |
import flashx.textLayout.elements.LinkElement; | |
import flashx.textLayout.elements.ParagraphElement; | |
import flashx.textLayout.elements.SpanElement; | |
import flashx.textLayout.elements.TextFlow; | |
import flashx.textLayout.formats.TextAlign; | |
import flashx.textLayout.formats.TextDecoration; | |
import flashx.textLayout.formats.TextLayoutFormat; | |
public class ConfigurationExample extends Sprite | |
{ | |
public function ConfigurationExample() | |
{ | |
//create container for the text and add to stage | |
var textContainer:Sprite = new Sprite(); | |
textContainer.x = 50; | |
textContainer.y = 20; | |
this.stage.addChild( textContainer ); | |
// create Configuration, set properties for it and add to TextFlow | |
var config:Configuration = new Configuration(); | |
var textLayoutFormat:TextLayoutFormat = new TextLayoutFormat(); | |
textLayoutFormat.fontFamily = "Arial, Helvetica, _sans"; | |
textLayoutFormat.fontSize = 16; | |
textLayoutFormat.kerning = Kerning.ON; | |
textLayoutFormat.fontStyle = FontPosture.ITALIC; | |
textLayoutFormat.textAlign = TextAlign.CENTER; | |
config.textFlowInitialFormat = textLayoutFormat; | |
var linkNormalFormat:TextLayoutFormat = new TextLayoutFormat(); | |
// make links red and underlined | |
linkNormalFormat.color = 0xFF0000; | |
linkNormalFormat.textDecoration = TextDecoration.UNDERLINE; | |
config.defaultLinkNormalFormat = linkNormalFormat; | |
// set selection color to light blue | |
var selectionFormat:SelectionFormat = new SelectionFormat(0x333300); | |
config.focusedSelectionFormat = selectionFormat; | |
var textFlow:TextFlow = new TextFlow(config); | |
// make text selectable | |
var selectionManager:SelectionManager = new SelectionManager(); | |
textFlow.interactionManager = selectionManager; | |
// create paragraph, a span of text, and a link | |
var p:ParagraphElement = new ParagraphElement(); | |
var span:SpanElement = new SpanElement(); | |
var linkSpan:SpanElement = new SpanElement(); | |
var link:LinkElement = new LinkElement(); | |
link.href = "http://www.adobe.com"; | |
linkSpan.text = "Adobe's website"; | |
link.addChild(linkSpan); | |
span.text = "The best place to go for information about Adobe products is: "; | |
// Add span and link to paragraph; add paragraph to TextFlow | |
p.addChild(span); | |
p.addChild(link); | |
textFlow.addChild(p); | |
// Add a controller for the container; specify container width and height | |
textFlow.flowComposer.addController(new ContainerController(textContainer, 80, 300)); | |
textFlow.flowComposer.updateAllControllers(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Only 45 lines of code to do this REALLY?