HTML inside XML

Bước 1:

_ Tạo FLA Document lưu với tên “ViewHTMLInsideXML.fla”.

_ Trên stage tạo 1 textField tên “htmlText_txt”.

_ Chọn font chữ Unicode nếu dùng tiếng Việt. Ở đây dùng Verdana.

Bước 2:

Tạo file “htmlText.xml”

<?xml version=”1.0″ encoding=”UTF-8″?>
<testi>
<testo_html><![CDATA[<p align="left"><b>YokoVNFX</b></p>
<p><b>Diễn đàn Flash Việt Nam</b></p>
<p><a href="http://www.vnfx.com"><i>Tutorial</i></a><br>Hiển thị định dạng <b>HTML</b> trong <b>XML</b></p>]]></testo_html>
</testi>

Bước 3:

Tạo file “ViewHtml.as” trong thư mục “com”

CODE:

package com {
import flash.text.TextField;
import flash.events.*;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.xml.*;
import flash.text.TextFieldAutoSize;

/**
* @author yoko
*/
public class ViewHtml {
private var HTML_TEXT : TextField;

public function ViewHtml(TXT : TextField) {
HTML_TEXT = TXT;
HTML_TEXT.multiline = true;
HTML_TEXT.autoSize = TextFieldAutoSize.LEFT;
loadXML();
}

private function loadXML() : void {
var loader : URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, completeHandler);

var request : URLRequest = new URLRequest(‘htmlText.xml’);
try {
loader.load(request);
}
catch(error : Error) {
trace(‘Unable to load requested document.’);
}
}

private function completeHandler(event : Event) : void {
var loader : URLLoader = URLLoader(event.target);
var result : XML = new XML(loader.data);
var myXML : XMLDocument = new XMLDocument();
myXML.ignoreWhite = true;
myXML.parseXML(result.toXMLString());
var node : XMLNode = myXML.firstChild;
HTML_TEXT.htmlText = node.firstChild.firstChild.nodeValue;
}
}
// class

}

Bước 4:

Mở file “ViewHTMLInsideXML.fla” chọn frame 1 code

import com.ViewHtml;
new ViewHtml(test_txt);

Bước 5:

Lưu lại nhấn Ctrl+Enter để chạy thử

Gửi phản hồi

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Thay đổi )

Twitter picture

You are commenting using your Twitter account. Log Out / Thay đổi )

Facebook photo

You are commenting using your Facebook account. Log Out / Thay đổi )

Connecting to %s

Follow

Get every new post delivered to your Inbox.