ActionScript 3 flash中的基本富文本编辑器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 flash中的基本富文本编辑器相关的知识,希望对你有一定的参考价值。

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);
		}
		
	}
}

以上是关于ActionScript 3 flash中的基本富文本编辑器的主要内容,如果未能解决你的问题,请参考以下文章

动画未在 actionscript 3.0 (flash cc) 中启动

ActionScript 3 Flash中的Maskenverlauf

Flash/ActionScript 中的类似 QTVR 的全景图?

Actionscript 3中的伪线程(对于Flash)

ActionScript 3 Flash画廊效果中的AS3 3D旋转螺旋

《Flash ActionScript 3 殿堂之路》十二 章,数组