[AS3] 텍스트의 조작

Programming/ActionScript 3.0 2007. 6. 15. 16:53
flash.text 패키지내에 있다. TextField 클래스를 사용하면 다이나믹 텍스트 필드 및 텍스트 입력 필드를 조작할 수 있다. flash.text 패키지에는 StaticText 클래스도 있지만 StaticText 오브젝트는 오로지 Flash authoring tool로 작성되기 때문에 ActionScript에서 인스턴스화할 수 없습니다.

다음의 예에 나타나듯이 TextFormat 오브젝트를 사용하여 TextField 전체 또는 임의의 범위의 텍스트의 포맷을 설정할 수 있다.








var tf:TextField = new TextField();
tf.text = "Hello Hello";

var format1:TextFormat = new TextFormat();
format1.color = 0xFF0000;

var format2:TextFormat = new TextFormat();
format2.font = "Courier";

tf.setTextFormat(format1);
var startRange:uint = 6;
tf.setTextFormat(format2, startRange);

addChild(tf);

Text 필드에는 plaintext 또는 HTML 형식의 텍스트의 어느쪽이든 포함할 수 있다. plaintext는 인스턴스의 text 프롭퍼티에 포함되어 HTML 텍스트는 htmlText 프롭퍼티에 포함된다.

다음 예와 같이 StyleSheet 오브젝트를 사용해 CSS 스타일 시트를 HTML 텍스트에 적용할 수 있다.

var style:StyleSheet = new StyleSheet();

var styleObj:Object = new Object();
styleObj.fontSize = "bold";
styleObj.color = "#FF0000";
style.setStyle(".darkRed", styleObj);

var tf:TextField = new TextField();
tf.text ="Hello Hello";
tf.styleSheet = style;
tf.htmlText = "<span class = 'darkRed'>Red</span> apple";

addChild(tf);


    

설정

트랙백

댓글