/ Published in: ActionScript 3
This is very basic but shows how to insert bold in a text a input text field. And how to view the "HTML code".
For more advance and complete editor check this out: http://code.google.com/p/as3texteditor/
Expand |
Embed | Plain Text
package com.RichTextEditor { import flash.display.MovieClip; import flash.events.*; import flash.text.*; import flash.events.* import fl.controls.*; import fl.controls.Button; public class richTextEditor extends MovieClip { //Declarations public var btnB:Button; public var btnCode:Button; public var input_txt:TextField; public function richTextEditor() { if (stage) init(); else addEventListener(Event.ADDED_TO_STAGE, init); } private function init(e:Event = null):void { removeEventListener(Event.ADDED_TO_STAGE, init); //Add a input textfiled to do the editing in. var abc:TextField = new TextField(); input_txt = abc; abc.width = 510; abc.height = 250; abc.x = 15; abc.y = 100; abc.htmlText='Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.'; abc.border = true; abc.wordWrap = true; abc.useRichTextClipboard = true; abc.multiline = true; abc.type = TextFieldType.INPUT; abc.background = true; abc.alwaysShowSelection = true; abc.backgroundColor = 0xFFFFFF; abc.doubleClickEnabled = true; abc.alwaysShowSelection = true; addChild(abc); //Add a buttons on the stage and name it btnB btnB.addEventListener(MouseEvent.CLICK, onBClick); btnB.label = "B" //And one called btnCode btnCode.addEventListener(MouseEvent.CLICK, onCodeClick); btnCode.label = "Code" } private function onCodeClick(e:MouseEvent):void { trace(input_txt.htmlText); } private function onBClick(e:MouseEvent):void { if ((input_txt.selectionBeginIndex == 0) && (input_txt.selectionEndIndex == 0)) return; if (input_txt.selectionBeginIndex == input_txt.selectionEndIndex) return; //JMW - this fixes a crash that occurs if they don't have any text selected but change the style. var my_fmt:TextFormat = input_txt.getTextFormat(input_txt.selectionBeginIndex, input_txt.selectionEndIndex); my_fmt.bold = !my_fmt.bold; input_txt.setTextFormat(my_fmt, input_txt.selectionBeginIndex, input_txt.selectionEndIndex); } } }
You need to login to post a comment.
