July 19, 2010
Posted by admin
TextLayoutFramework Fun
So, I though I would post some findings about the tlf that have been coming up recently in my irc/forums
Problem : Links in the spark TextArea don’t dispatch
Solution : Make sure that you set textArea.mouseChildren=true and/or textArea.textDisplay.mouseChildren = true
Problem : I need to create dynamic elements and append to the main textFlow ( ie chat system)
Solution:
var mainTextFlow:TextFlow
var importer:ITextImporter = TextConverter.getImporter(TextConverter.TEXT_LAYOUT_FORMAT, v);
var flowMarkupToAdd:String=<flow:TextFlow xmlns:flow = 'http://ns.adobe.com/textLayout/2008'>
<flow:div id='container' color='{messageColor}' fontStyle='{fontStyle}' fontSize='{messageSize}' fontFamily='{messageFont}'>{message}</flow:div></flow:TextFlow>;
var newTextFlow:TextFlow = importer.importToFlow(flowMarkupToAdd)
if (importer.errors) // check for errors
{
for each (var error:String in importer.errors)
{
trace("addLine:: Error", error);
}
}
mainTextFlow.addChild(newTextFlow.getElementByID('container').deepCopy()); // deep copy container and add to main text flowProblem : How do I listen to custom events from a LinkElement?
Solution :
var link:LinkElement = new LinkElement();
link.href="event:helloWorld";
textFlow.addChild(link);
var span:SpanElement = new SpanElement();
span.text="hello";
link.addChild(span);
textFlow.addEventListener("helloWorld",textFlow_clickHandler);
function textFlow_clickHandler(e:FlowElementMouseEvent):void{
var link:LinkElement = LinkElement(e.flowElement);
trace("My Link ",link.getText()) // should output "hello"
}
Hopefully this will help some folks out
No Comments Yet
You can be the first to comment!
Leave a comment