forked from: TextField で CSS 適用済み HTML を表示する

by takeshi81 forked from TextField で CSS 適用済み HTML を表示する (diff: 3)
HTML タグに関してはあえて対応していないタグを使用(もちろん推奨されません)。
id 属性は使用できないっぽい?

Flash Player で対応している HTML タグ一覧
http://livedocs.adobe.com/flex/3_jp/langref/flash/text/TextField.html#htmlText

Flash Player で対応している CSS プロパティ一覧
http://livedocs.adobe.com/flex/3_jp/langref/flash/text/StyleSheet.html

...
@author tkinjo
♥0 | Line 29 | Modified 2009-10-05 00:48:44 | MIT License
play

ActionScript3 source code

/**
 * Copyright takeshi81 ( http://wonderfl.net/user/takeshi81 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/536h
 */

// forked from tkinjo's TextField で CSS 適用済み HTML を表示する
package  
{
	/**
	 * HTML タグに関してはあえて対応していないタグを使用(もちろん推奨されません)。
	 * id 属性は使用できないっぽい?
	 * 
	 * Flash Player で対応している HTML タグ一覧
	 * http://livedocs.adobe.com/flex/3_jp/langref/flash/text/TextField.html#htmlText
	 * 
	 * Flash Player で対応している CSS プロパティ一覧
	 * http://livedocs.adobe.com/flex/3_jp/langref/flash/text/StyleSheet.html
	 */
	
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.text.StyleSheet;
	import flash.text.TextField;
	
	[SWF(width="465", height="465", frameRate="60", backgroundColor="0xffffff")]
	/**
	 * ...
	 * @author tkinjo
	 */
	public class Main extends Sprite
	{
		
		/**
		 * 
		 */
		public function Main() 
		{
			var htmlTextField:TextField = new TextField();
			htmlTextField.width = stage.stageWidth;
			htmlTextField.height = stage.stageHeight;
			htmlTextField.multiline = true;	//フィールドが複数行テキストフィールドであるかどうかを示します。
			htmlTextField.condenseWhite = true;	//HTML テキストが含まれるテキストフィールド内の余分な空白(スペース、改行など)を削除するかどうかを指定するブール値です。
			addChild( htmlTextField );
			
			//var htmlLoader:URLLoader = new URLLoader();
			//htmlLoader.addEventListener( Event.COMPLETE, function( event:Event ):void {
					//
					//htmlTextField.htmlText = htmlLoader.data;
				//} );
			//
			//var cssLoader:URLLoader = new URLLoader();
			//cssLoader.addEventListener( Event.COMPLETE, function( event:Event ):void {
					
					var styleSheet:StyleSheet = new StyleSheet();
					//styleSheet.parseCSS( cssLoader.data );
					styleSheet.parseCSS( cssText );
					htmlTextField.styleSheet = styleSheet;
					
					// スタイルシート読み込み後にテキストフィールドのテキストを設定しなければスタイルシートは設定されない。
					//htmlLoader.load( new URLRequest( "assets/news.html" ) );
				//} );
			//cssLoader.load( new URLRequest( "assets/style.css" ) );
			
			htmlTextField.htmlText = htmlText;
		}
		
		private const cssText:String = 'h3,ul{font-family:"メイリオ,Meiryo,MS Pゴシック,MS PGothic,_sans";font-size:20pt;}.arial{font-family:"Arial,Helvetica,_sans";}.times{font-family:"Times,Times New Roman,_serif";}.comic{font-family:"Comic Sans MS,_fancy";}';
		private const htmlText:String = '<h3>Textfield with CSS</h3><ul><li class="arial">This is Arial.</li><li class="times">This is Times.</li><li class="comic">This is Comic Sans.</li><ul>';
	}
	
}

Forked