Chapter 18 Example 7
♥0 |
Line 57 |
Modified 2009-12-14 17:11:59 |
MIT License
archived:2017-03-30 03:23:58
ActionScript3 source code
/**
* Copyright actionscriptbible ( http://wonderfl.net/user/actionscriptbible )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/cSa6
*/
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.*;
import flashx.textLayout.compose.StandardFlowComposer;
import flashx.textLayout.container.ContainerController;
import flashx.textLayout.conversion.TextConverter;
import flashx.textLayout.edit.TextClipboard;
import flashx.textLayout.edit.TextScrap;
import flashx.textLayout.elements.*;
public class ch18ex7 extends Sprite {
protected var flow:TextFlow;
public function ch18ex7() {
flow = TextConverter.importToFlow("Cellar door",
TextConverter.PLAIN_TEXT_FORMAT);
flow.fontFamily = "_typewriter";
flow.fontSize = 11;
flow.flowComposer = new StandardFlowComposer();
var container:Sprite = new Sprite();
addChild(container); container.x = 10; container.y = 10;
var containerController:ContainerController =
new ContainerController(container, 300, 20);
flow.flowComposer.addController(containerController);
flow.flowComposer.updateAllControllers();
var button:TestButton = new TestButton(100, 20, "Copy");
button.addEventListener(MouseEvent.CLICK, onClick);
addChild(button); button.x = 320; button.y = 10;
//textfield to try pasting to afterwards
var tf:TextField = new TextField();
tf.type = TextFieldType.INPUT;
tf.defaultTextFormat = new TextFormat("_typewriter", 11);
tf.width = 410; tf.height = 100;
tf.border = true;
tf.wordWrap = tf.multiline = true;
tf.text = "Try pasting the result here.";
addChild(tf); tf.x = 10; tf.y = 40;
}
protected function onClick(event:MouseEvent):void {
TextClipboard.setContents(
TextScrap.createTextScrap(new TextRange(flow, 0, flow.textLength)));
}
}
}
import flash.display.*;
import flash.text.*;
class TestButton extends Sprite {
public var label:TextField;
public function TestButton(w:Number, h:Number, labelText:String) {
graphics.lineStyle(0.5, 0, 0, true); graphics.beginFill(0xa0a0a0);
graphics.drawRoundRect(0, 0, w, h, 8);
label = new TextField(); addChild(label);
label.defaultTextFormat = new TextFormat("_sans", 11, 0, true, false,
false, null, null, "center");
label.width = w; label.height = h; label.text = labelText;
label.y = (h - label.textHeight)/2 - 2;
buttonMode = true; mouseChildren = false;
}
}