Flash / Flex / ActionScript/TextField/htmlText
Содержание
- 1 Add a Hyperlink to Text with target
- 2 Add HTML new line tag in TextField
- 3 Adding a Hyperlink to Text
- 4 Adding Mail Links
- 5 Calling JavaScript Functions
- 6 Condensing Whitespace
- 7 Displaying HTML-Formatted Text
- 8 Embed a SWF file
- 9 Embedding Content in Text
- 10 Escape HTML tags bracket
- 11 Formatting Text by using HTML tags
- 12 Formatting Text with HTML
- 13 Interactions between the text and htmlText variables
- 14 Make the text font italic
- 15 Quoting attribute values
- 16 Set both text and htmlText
- 17 Set link color
- 18 Specify a target window into which the link opens
- 19 Use HTML hyperlink in TextField
- 20 Use html text in TextField
- 21 Use HTML to make the text bold
- 22 Use img tag in TextField
Add a Hyperlink to Text with target
package {
import flash.display.Sprite;
import flash.text.TextField;
public class Main extends Sprite {
public function Main( ) {
var field:TextField = new TextField( );
field.htmlText = "<a href="http://www.wbex.ru" target="blank">Website</a>";
addChild(field);
}
}
}
Add HTML new line tag in TextField
package{
import flash.display.Sprite;
import flash.text.*;
public class Main extends Sprite{
public function Main(){
var tArticle:TextField = new TextField();
tArticle.multiline = true;
tArticle.wordWrap = true;
for(var i:Number = 0; i < 100; i++) {
tArticle.htmlText += "<b>item</b><br>";
}
}
}
}
Adding a Hyperlink to Text
package {
import flash.display.Sprite;
import flash.text.TextField;
public class Main extends Sprite {
public function Main( ) {
var field:TextField = new TextField( );
field.htmlText = "<a href="http://www.wbex.ru">Website</a>";
addChild(field);
}
}
}
Adding Mail Links
package{
import flash.display.Sprite;
import flash.text.*;
public class Main extends Sprite{
public function Main(){
var tArticle:TextField = new TextField();
tArticle.multiline = true;
tArticle.wordWrap = true;
tArticle.htmlText = <a href=mailto:joey@wbex.ru>send email</a>;
addChild(tArticle);
}
}
}
Calling JavaScript Functions
package{
import flash.display.Sprite;
import flash.text.*;
public class Main extends Sprite{
public function Main(){
var tArticle:TextField = new TextField();
tArticle.multiline = true;
tArticle.wordWrap = true;
tArticle.htmlText = "<a href=\"javascript:void(alert("This is a message from Flash"));\">click this text</a>";
addChild(tArticle);
}
}
}
Condensing Whitespace
package {
import flash.display.Sprite;
import flash.text.TextField;
public class Main extends Sprite {
public function Main( ) {
var field:TextField = new TextField( );
field.condenseWhite = true;
field.htmlText = "hello friend"; // Displays: "hello friend"
addChild(field);
}
}
}
Displaying HTML-Formatted Text
package {
import flash.display.Sprite;
import flash.text.TextField;
public class Main extends Sprite {
public function Main( ) {
var field:TextField = new TextField( );
field.htmlText = "<u>This displays as underlined text.</u>";
field.text = "<u>underlined text</u>"; addChild(field);
}
}
}
Embed a SWF file
package{
import flash.display.Sprite;
import flash.text.*;
public class Main extends Sprite{
public function Main(){
var txt:TextField = new TextField();
txt.htmlText = "<img src="Movie.swf" id=" textMovie" width="100" height="100" /> some text around our image";
addChild(txt);
}
}
}
Embedding Content in Text
package{
import flash.display.Sprite;
import flash.text.*;
public class Main extends Sprite{
public function Main(){
var tContent:TextField = new TextField();
tContent.border = true;
tContent.htmlText = "A picture of a lake: <img width="180" height="120" src="http://www.wbex.ru/asb/image2.jpg">";
addChild(tContent);
}
}
}
Escape HTML tags bracket
package{
import flash.display.Sprite;
import flash.text.*;
public class Main extends Sprite{
public function Main(){
var tTitle:TextField = new TextField();
tTitle.htmlText = "< is a less than sign";
addChild(tTitle);
}
}
}
Formatting Text by using HTML tags
package {
import flash.display.Sprite;
import flash.text.TextField;
public class Main extends Sprite {
public function Main( ) {
var field:TextField = new TextField( );
field .htmlText = "<b>Bold text</b> <u>Underlined text</u>";
addChild(field);
}
}
}
Formatting Text with HTML
package{
import flash.display.Sprite;
import flash.text.*;
public class Main extends Sprite{
public function Main(){
var t:TextField = new TextField( );
t.autoSize = TextFieldAutoSize.LEFT;
var message:String = "<FONT FACE="Arial" SIZE="20">"
+ "<B>ActionScript is fun!</B></FONT>";
t.htmlText = message;
//HTML text is assigned directly to the htmlText variable
t.htmlText = "<FONT FACE="Arial" SIZE="20">"
+ "<B>ActionScript is fun!</B></FONT>";
addChild(t);
}
}
}
Interactions between the text and htmlText variables
package{
import flash.display.Sprite;
import flash.text.*;
public class Main extends Sprite{
public function Main(){
var t:TextField = new TextField( );
t.htmlText = "<P ALIGN="LEFT">" +
+ "<FONT FACE="Times New Roman" SIZE="12" COLOR="#000000" "
+ "LETTERSPACING="0" KERNING="0">This field contains <B>HTML!</B>"
+ "</FONT></P>";
addChild(t);
}
}
}
Make the text font italic
package{
import flash.display.Sprite;
import flash.text.*;
public class Main extends Sprite{
public function Main(){
var tArticle:TextField = new TextField();
tArticle.multiline = true;
tArticle.wordWrap = true;
var sTempHTML:String = "<B>Bold text</B>";
sTempHTML += "<I>Italic text</I>";
tArticle.htmlText = sTempHTML;
addChild(tArticle);
}
}
}
Quoting attribute values
package{
import flash.display.Sprite;
import flash.text.*;
public class Main extends Sprite{
public function Main(){
var t:TextField = new TextField( );
t.htmlText = "<P ALIGN="RIGHT">hi there</P>";
addChild(t);
}
}
}
Set both text and htmlText
package{
import flash.display.Sprite;
import flash.text.*;
public class Main extends Sprite{
public function Main(){
var t:TextField = new TextField( );
t.htmlText = "<B>hello</B>";
t.text += " world";
addChild(t);
}
}
}
Set link color
package {
import flash.display.Sprite;
import flash.text.TextField;
public class Main extends Sprite {
public function Main( ) {
var field:TextField = new TextField( );
var htmlLink:String = "<font color="#0000FF"><u>";
htmlLink += "<a href="http://www.wbex.ru">Website</a>";
htmlLink += "</u></font>";
field.htmlText = htmlLink;
addChild(field);
}
}
}
Specify a target window into which the link opens
package {
import flash.display.Sprite;
import flash.text.TextField;
public class Main extends Sprite {
public function Main( ) {
var field:TextField = new TextField( );
field.text = "Website";
var formatter:flash.text.TextFormat = new flash.text.TextFormat( );
formatter.url = "http://www.wbex.ru/";
formatter.target = "_blank";
field.setTextFormat(formatter);
addChild(field);
}
}
}
Use HTML hyperlink in TextField
package{
import flash.display.Sprite;
import flash.text.*;
public class Main extends Sprite{
public function Main(){
var tContent:TextField = new TextField();
tContent.htmlText = "<a href="http://www.wbex.ru" target="_blank">www.wbex.ru</a>";
addChild(tContent);
}
}
}
Use html text in TextField
package {
import flash.display.Sprite;
import flash.text.TextField;
public class Main extends Sprite {
public function Main( ) {
var field:TextField = new TextField( );
htmlCode = "<i>italicized text</i>";
sourceHTML.text = htmlCode;
renderedHTML.htmlText = htmlCode;
addChild(field);
}
}
}
Use HTML to make the text bold
package{
import flash.display.Sprite;
import flash.text.*;
public class Main extends Sprite{
public function Main(){
var t:TextField = new TextField( );
t.htmlText = "This field contains <B>HTML!</B>";
trace(t.htmlText);
addChild(t);
}
}
}
Use img tag in TextField
package{
import flash.display.Sprite;
import flash.text.*;
public class Main extends Sprite{
public function Main(){
var tContent:TextField = new TextField();
tContent.htmlText = "A picture of a lake: <img id="mImage" width="180" height="120" align="center" vspace="0" hspace="0" src="http://www.wbex.ru/asb/image2.jpg">";
addChild(tContent);
}
}
}