# from ricardo Pedroso example .flash filename="as3_test.swf" bbox=620x440 version=9 fps=12 background=#666666 .edittext log width=400 height=80 border color=black multiline html wordwrap .put log x=0 y=425 .edittext edi width=400 height=400 border color=black multiline html .put edi 0 20 .edittext bold_e width=40 height=18 border color=black text="Bold" .button bold_b .show bold_e as=shape .show bold_e as=hover x=1 y=1 .end .edittext italic_e width=40 height=18 border color=red text="Italic" .button italic_b .show italic_e as=shape .show italic_e as=hover x=1 y=1 .end .edittext underl_e width=60 height=18 border color=blue text="Underline" .button underline_b .show underl_e as=shape .show underl_e as=hover x=1 y=1 .end .sprite toolbar .put bold_b .put italic_b x=50 .put underline_b x=100 .end .put toolbar 10 0 .action: package { import flash.display.* import flash.text.* import flash.events.*; public dynamic class Editor extends MovieClip { private function trace(s) { this.log.text+=s+"\n"; } public function Editor() { // trace(" "+this.toolbar); this.edi.backgroundColor = 0xffffcc; this.edi.useRichTextClipboard = true; this.edi.antiAliasType = AntiAliasType.ADVANCED; this.toolbar.bold_b.addEventListener(MouseEvent.CLICK, Format); this.toolbar.italic_b.addEventListener(MouseEvent.CLICK, Format); this.toolbar.underline_b.addEventListener(MouseEvent.CLICK, Format); } private function Format(e:MouseEvent): void { var n=e.target.name; var beg:Number =this.edi.selectionBeginIndex; var end:Number =this.edi.selectionEndIndex; trace(" "+beg+" -> "+end+" total "+this.edi.length); var fmt:TextFormat; if (beg == end) { if (beg-1 < 0) { beg=0; end=1 } else if (beg == this.edi.length) beg--; fmt = this.edi.getTextFormat(beg-1,end); } else fmt = this.edi.getTextFormat(beg,end); var newfmt:TextFormat= new TextFormat(); if (n =='bold_b' ) newfmt.bold = !fmt.bold; else if (n =='italic_b' ) newfmt.italic = !fmt.italic; else if (n =='underline_b' ) newfmt.underline = !fmt.underline; this.edi.setTextFormat(newfmt,beg,end); this.edi.defaultTextFormat = newfmt; } } } .end # action .end # flash