/**
* Copyright riafeed ( http://wonderfl.net/user/riafeed )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/dFmA
*/
package
{
import flash.display.*;
import flash.text.*;
import flash.text.engine.*;
import flash.events.*;
import flashx.textLayout.container.*;
import flashx.textLayout.elements.*;
import flashx.textLayout.formats.*;
import flashx.textLayout.conversion.TextConverter;
import spark.utils.TextFlowUtil;
//import fl.controls.NumericStepper;
public class Main extends MovieClip
{
private var string_1:String="";
private var string_2:String="";
private var string_3:String="";
private var string_4:String="";
private var holder_mc:MovieClip;
private var format_1:TextLayoutFormat;
private var format_2:TextLayoutFormat;
private var flow:TextFlow;
private var par_1:ParagraphElement;
private var par_2:ParagraphElement;
private var par_3:ParagraphElement;
private var par_4:ParagraphElement;
public function Main()
{
addEventListener(Event.ADDED_TO_STAGE,init);
}
private function init(evt:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE,init);
createHolder();
setStrings();
setFormats();
setFlow();
setParagraphs();
addFlow();
addNumericStepperEvents();
}
private function createHolder():void
{
holder_mc=new MovieClip();
addChild(holder_mc);
}
private function setStrings():void
{
string_1="<h2><b><font color=\"#FF0000\" size=\"20\">What is Lorem Ipsum?</font></b></h2>";
string_2="<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent vel eros urna, quis elementum tellus. "+
"Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</div>"
string_3="<h2><b>Where does it come from?</b></h2>";
string_4="<p>Quisque quis erat quis odio consectetur porta ac sit amet lectus."+
"Sed vel justo diam, eget ultrices ipsum. Duis sem velit, ornare at viverra eu, faucibus in nulla. "+
"Cras a tellus nec massa iaculis venenatis vitae vitae velit. "+
"Pellentesque bibendum leo at dui placerat non rutrum libero sodales. "+
"Donec faucibus, est vitae semper tempus, purus ipsum hendrerit ligula, ac consectetur nulla velit non nisl. "+
"Etiam tincidunt sapien in lorem tincidunt lacinia. Suspendisse fermentum fermentum vehicula. "+
"Etiam pellentesque felis eu sem ullamcorper ac congue urna dapibus. "+
"Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. "+
"Fusce elementum dignissim purus, eget commodo lacus egestas ac. "+
"Cras eleifend erat vel felis malesuada sed mollis nibh aliquam. "+
"Quisque adipiscing, justo quis semper rutrum, ante odio euismod erat, ac dignissim libero nulla id risus. "+
"Curabitur varius, lacus in mollis commodo, elit ante lacinia lacus, eu semper felis ipsum ut ante.</p>";
}
private function setFormats():void
{
format_1=new TextLayoutFormat();
format_2=new TextLayoutFormat();
format_1.color=0x999999;
format_1.fontFamily="Arial, Helvetica, _sans";
format_1.fontSize=14;
format_1.paragraphSpaceBefore=0;
format_1.paragraphSpaceAfter=20;
format_2.color=0x666666;
format_2.fontSize=16;
format_2.fontWeight=FontWeight.BOLD;
}
private function setFlow():void
{
//flow=new TextFlow();
//flow = TextFlowUtil.importFromString(string_1 + string_2);
flow = TextConverter.importToFlow(string_1 + string_2 + string_3 + string_4 , TextConverter.TEXT_FIELD_HTML_FORMAT);
flow.columnCount=1;
flow.columnGap=30;
flow.hostFormat=format_1;
}
private function setParagraphs():void
{
/*
par_1=new ParagraphElement();
par_2=new ParagraphElement();
par_3=new ParagraphElement();
par_4=new ParagraphElement();
var span_1:SpanElement=new SpanElement();
span_1.text=string_1;
par_1.addChild(span_1);
par_1.format=format_2;
flow.addChild(par_1);
var span_2:SpanElement=new SpanElement();
span_2.text=string_2;
par_2.addChild(span_2);
flow.addChild(par_2);
var span_3:SpanElement=new SpanElement();
span_3.text=string_3;
par_3.addChild(span_3);
par_3.format=format_2;
flow.addChild(par_3);
var span_4:SpanElement=new SpanElement();
span_4.text=string_4;
par_4.addChild(span_4);
flow.addChild(par_4);
*/
//flow = TextConverter.importToFlow(string_1 + string_2 + string_3 + string_4 , TextConverter.TEXT_LAYOUT_FORMAT);
}
private function addFlow():void
{
flow.flowComposer.addController(new ContainerController(holder_mc,400,400));
flow.flowComposer.updateAllControllers();
holder_mc.x=stage.stageWidth/2-holder_mc.width/2;
holder_mc.y=stage.stageHeight/2-holder_mc.height/2;
}
private function addNumericStepperEvents():void
{
//numeric_mc.stepSize=1;
//numeric_mc.maximum=5;
//numeric_mc.minimum=1;
//numeric_mc.value=1;
//numeric_mc.addEventListener(Event.CHANGE,onStepperChange);
}
function onStepperChange(evt:Event):void
{
var n:Number=evt.target.value;
flow.columnCount=n;
flow.flowComposer.updateAllControllers();
}
}
}