flash on 2010-3-4
動かないけどね
♥0 |
Line 54 |
Modified 2010-03-04 23:52:34 |
MIT License
archived:2017-03-20 02:51:19
ActionScript3 source code
/**
* Copyright foo9 ( http://wonderfl.net/user/foo9 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/30vS
*/
//動かないけどね
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.events.Event;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.system.Security;
[SWF(backgroundColor="#cccccc", width="465", height="465")]
public class NamesapceTest extends Sprite {
public static const RSS:String = "http://www.nicovideo.jp/newarrival";
public static const CROSSDOMAIN:String = "http://www.nicovideo.jp/crossdomain.xml";
public static const XMLNS:Namespace = new Namespace("http://purl.org/rss/1.0/");
public static const XMLNS_DC:Namespace = new Namespace("http://purl.org/dc/elements/1.1/");
private var console:Console;
public function NamesapceTest() {
Security.loadPolicyFile(CROSSDOMAIN);
init();
}
private function init():void {
console = new Console(465, 465);
addChild(console);
console.print("Initialize");
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
loader.load(new URLRequest(RSS));
console.print("RSS Loading...");
}
private function completeHandler(event:Event):void{
console.print("Complete RSS Load !");
var xml:XML = new XML(event.target.data);
/*
var str:String = "";
for each(var tmp:XML in getItemNode(xml)) {
//str += tmp.toString();
for each(var tmp2:XML in getItemDate(tmp)) {
//str += tmp2.toString() + "\n";
}
}
console.print(str);
*/
console.print(xml.toString());
console.print("End.");
}
private function getItemNode(xml:XML):XMLList { return XMLUtils.getAttributeByNameNS(xml,XMLNS,"item"); }
private function getItemDate(xml:XML):XMLList { return XMLUtils.getAttributeByNameNS(xml,XMLNS_DC,"date"); }
}
}
//****************************************************************************************************
import flash.errors.IllegalOperationError;
class XMLUtils {
public function XMLUtils() {
throw new IllegalOperationError();
}
public static function getAttributeByNameNS(xml:XML, ns:Namespace, name:String):XMLList {
return xml.ns::[name];
}
}
//****************************************************************************************************
import flash.text.TextField;
class Console extends TextField {
public function Console(w:Number=465, h:Number=465) {
super.width = w;
super.height = h;
}
public function print(text:String):void { this.text = this.text + text + "\n"; }
}