forked from: forked from: 青空文庫のテキストを取得

by ongaeshi forked from forked from: 青空文庫のテキストを取得 (diff: 1)
♥0 | Line 36 | Modified 2010-01-10 17:44:54 | MIT License
play

ActionScript3 source code

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

// forked from ongaeshi's forked from: 青空文庫のテキストを取得
// forked from umhr's 青空文庫のテキストを取得
/*
 * http://pipes.yahoo.com/pipes/pipe.info?_id=68fa588146242e845cbac5f0ce3804a2
 * 
 * http://www.aozora.gr.jp/cards/000879/files/3814_27290.html
 * */

package 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	import flash.net.URLLoader;
	import flash.net.navigateToURL;
	import flash.text.TextField;
	import com.adobe.serialization.json.JSON;
	/**
	 * ...
	 * @author umhr
	 */
	[SWF(backgroundColor="0xF0F8FF")]
	public class Main extends Sprite 
	{
		public function Main():void 
		{
			var myURLLoader:URLLoader = new URLLoader();
			myURLLoader.addEventListener (Event.COMPLETE, onCompleteJSON);
			//YahooPipesの汎用feedPage
			var jsonURL:String = "http://pipes.yahooapis.com/pipes/pipe.run?_id=68fa588146242e845cbac5f0ce3804a2&_render=json&url=";
			//encodeURIComponentでエスケープして、feedProxyにくっつける。
			jsonURL += encodeURIComponent("http://www.aozora.gr.jp/cards/000148/files/1046_14938.html");
			myURLLoader.load(new URLRequest(jsonURL));
		}
           
		private function onCompleteJSON(e:Event):void 
		{
			//jsonとして受け取る
			var json:Object = JSON.decode(e.target.data);
			var jsonString:String = json.value.items[0].content;

                        // trace("jsonString(prev)");
                        // trace(jsonString);

			//正規表現で不要なタグを削除
			jsonString = jsonString.replace(/<r.>|<\/r.>|<ruby>|<\/ruby>/g, "");
			//XML型にする
			var bookXML:XML = new XML(jsonString);

                        //trace("jsonString");
                        //trace(jsonString);
                        //trace("bookXML");
                        //trace(bookXML);
			
			//テキストフィールドを作りXMLを流し込む
			var myTextField:TextField = new TextField();
			myTextField.width = 465;
			myTextField.height = 465;
                        // myTextField.text = bookXML;
			myTextField.htmlText = bookXML;
                        //myTextField.htmlText = jsonString;
                        //myTextField.htmlText = json.value.items[0].content;
			myTextField.wordWrap = true;
			addChild(myTextField);
		}
	}
}