In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: twitter APIで検索

twitter API叩いて、XMLの処理して、表示。
serch!でサーチ開始。
TextField編集でサーチする文字変更。(日本語は無理?)
リンクを右クリック、新規ウインドウで開く、でそのリンク開く。(wonderfl上ではそのままクリックしても開かない?)

いささか力技な感が。
コードは汚いので以下のサイト参考にした方がいいかもね。

FlashでTwitterの発言を取得してみる
@see  http://blog.alt-scape.com/archives/234

ActionScript3.0 E4X
@see http://kozy.heteml.jp/pukiwiki/ActionScript3.0%2520E4X/index.html

[ActionScript3.0] RSS読み込み(xmlns デフォルト名前空間の処理)
@see http://moringo.moo.jp/wordpress/?p=6

@author coppieee
/**
 * Copyright torq_andy ( http://wonderfl.net/user/torq_andy )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/zjIZ
 */

// forked from coppieee's twitter APIで検索
package 
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.IOErrorEvent;
    import flash.events.MouseEvent;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.text.StyleSheet;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFieldType;
    
    /**
     * twitter API叩いて、XMLの処理して、表示。
     * serch!でサーチ開始。
     * TextField編集でサーチする文字変更。(日本語は無理?)
     * リンクを右クリック、新規ウインドウで開く、でそのリンク開く。(wonderfl上ではそのままクリックしても開かない?)
     * 
     * いささか力技な感が。
     * コードは汚いので以下のサイト参考にした方がいいかもね。
     * 
     * FlashでTwitterの発言を取得してみる
     * @see  http://blog.alt-scape.com/archives/234
     * 
     * ActionScript3.0 E4X
     * @see http://kozy.heteml.jp/pukiwiki/ActionScript3.0%2520E4X/index.html
     * 
     * [ActionScript3.0] RSS読み込み(xmlns デフォルト名前空間の処理)
     * @see http://moringo.moo.jp/wordpress/?p=6
     * 
     * @author coppieee
     */
    public class Main extends Sprite 
    {
        private var atom:Namespace = new Namespace("http://www.w3.org/2005/Atom");
        public function Main():void 
        {
            Wonderfl.capture_delay(5);
    
            var button:Sprite  = new Sprite();
            var btf:TextField = new TextField();
            btf.text = "search!";
            btf.selectable = false;
            btf.backgroundColor = 0x000000;
            btf.textColor = 0xFFFFFF;
            btf.background = true;
            btf.border = true;
            btf.autoSize = TextFieldAutoSize.LEFT;
            button.addChild(btf);
            addChild(button);
            
            var serchTextField:TextField = new TextField();
            serchTextField.type = TextFieldType.INPUT;
            serchTextField.border = true;
            serchTextField.text = "wonderfl";
            serchTextField.x = 60;
            serchTextField.height = 20;
            addChild(serchTextField);
            
            var tf:TextField = new TextField();
            tf.y = 20;
            tf.width = 412;
            tf.height = 412 - 20;
            tf.multiline = true;
            tf.wordWrap = true;
            tf.selectable = true;
            addChild(tf);
            var ss:StyleSheet = new StyleSheet();
            ss.setStyle("a:link", { textDecoration:"underline", color:"#0000FF" } );
            tf.styleSheet = ss;
            
            var f:Function;
            button.addEventListener(MouseEvent.CLICK,f = function(e:MouseEvent):void {
                var loader:URLLoader = new URLLoader();
                loader.addEventListener(Event.COMPLETE, function(e:Event):void {
                    default xml namespace = atom;
                    var entrys:XMLList = XML(loader.data).entry;
                    var s:String = "<br/>";
                    for each(var x:XML in entrys)
                    {
                        s+= entryToString(x);
                    }
                    tf.htmlText = s;
                });
                loader.addEventListener(IOErrorEvent.IO_ERROR, function(e:IOErrorEvent):void {
                    trace(e);
                });
                loader.load(new URLRequest("http://search.twitter.com/search.atom?q="+serchTextField.text+""));
                
            });
            f(null);
        }
        private function entryToString(entry:XML):String
        {
            var s:String = "<p><img src='"+entry.link.(@type=="image/png")[0].@href+"' width='20' height='20' /></p>"
            + "<p><a href='" + entry.link.(@type=="text/html")[0].@href +"'>" + entry.author[0].name + '</a></p>'
            + "<p>"+ entry.title[0] + "</p>";
            return s;
        }
    }
}