Skip to content

Instantly share code, notes, and snippets.

@kristoferjoseph
Created August 26, 2011 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kristoferjoseph/1174512 to your computer and use it in GitHub Desktop.
Save kristoferjoseph/1174512 to your computer and use it in GitHub Desktop.
It's SO easy to style a hyperlink in Flex
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();
}
}
}
@kristoferjoseph
Copy link
Author

Only 45 lines of code to do this REALLY?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment