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の検索z軸つき

Twitter Search API Method: search
* http://apiwiki.twitter.com/Twitter-Search-API-Method%3A-search
* 
* Twitter API 仕様書 (勝手に日本語訳シリーズ)

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

/*
 * Twitter Search API Method: search
 * http://apiwiki.twitter.com/Twitter-Search-API-Method%3A-search
 * 
 * Twitter API 仕様書 (勝手に日本語訳シリーズ)

 * */
package {
    
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.DisplayObject;
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.IOErrorEvent;
    import flash.events.KeyboardEvent;
    import flash.events.MouseEvent;
    import flash.events.TextEvent;
    import flash.filters.DropShadowFilter;
    import flash.geom.PerspectiveProjection;
    import flash.geom.Point;
    import flash.net.URLRequest;
    import flash.net.URLLoader;
    import flash.net.navigateToURL;
    import flash.text.TextField;
    import flash.text.TextFieldType;
    import flash.net.navigateToURL;
    import flash.display.DisplayObjectContainer;
    import flash.geom.Vector3D;
    import org.libspark.betweenas3.BetweenAS3;
    import org.libspark.betweenas3.tweens.ITween;
    import org.libspark.betweenas3.easing.*;
    import com.bit101.components.PushButton;
    import com.bit101.components.InputText;

    
    /**
     * ...
     * @author umhr
     */
    
    
    
    public class MainTwitterV2 extends Sprite {
        private var _resultStage:Sprite;
        private var sp:Sprite;
        private var myTextField:TextField;
        private var _twitterUser:String;
         private var _t:ITween;
         private var _num:int = 400;
         private var btnUp:PushButton;
         private var btnDown:PushButton;
         private var _input:InputText;
         private var btnRe:PushButton;
         
        public function MainTwitterV2 ():void {
            _input = new InputText(this, 5, 5, "Bob Dylan");
            _input.width = 120;
            _input.height = 20;
            _input.maxChars = 90;
            btnRe =  new PushButton(this, 160, 5, "Search", onKeyUp);
            btnUp = new PushButton(this, 200, 40, "Up", onClickUp);
            btnUp.width = 44;
            btnDown = new PushButton(this, 200, 420, "Down", onClickDown);
            btnDown.width = 44;
            _resultStage = new Sprite();
            _resultStage.y = 0;
            //_resultStage.z = 0;
            addChildAt(_resultStage,0);
            serch(_input.text)
        }
        
        private function onKeyUp(event:MouseEvent):void {
           serch(_input.text)
        }
        
        public function serch(serchWord:String):void {
            //検索APIにリクエストを投げる
            //http://search.twitter.com/crossdomain.xml上で許可をしているので
         
            var myURLLoader:URLLoader = new URLLoader();
            myURLLoader.addEventListener(Event.COMPLETE, onCompleteXML);
            myURLLoader.addEventListener(IOErrorEvent.IO_ERROR, onIoError);
            var xmlURL:String = "http://search.twitter.com/search.atom?q=";
            //encodeURIComponent()を使うことによって、#や日本語にも対応
            xmlURL += encodeURIComponent(serchWord);        //*1
            myURLLoader.load(new URLRequest(xmlURL));
        }
        
        public function onIoError(e:IOErrorEvent):void {
            trace("error"+e.type);
            
        }
        private function onCompleteXML(e:Event):void {
            //eventListener
            e.currentTarget.removeEventListener(Event.COMPLETE, onCompleteXML);
            //_resultStage
            while (_resultStage.numChildren) {
                _resultStage.removeChildAt(0);
                _resultStage.z = -250;
            }
            var myXML:XML = new XML(e.currentTarget.data);
            default xml namespace = new Namespace("http://www.w3.org/2005/Atom");        //*2
            var itemLength:int = myXML.entry.length();
               for (var i:int = 0; i < itemLength; i++) {
                var link:String = myXML.entry[i].link[0].@href;
                var authorName:String = myXML.entry[i].author.name;
                var title:String = myXML.entry[i].title;
                var linkFinder:FindURL = new FindURL(title);
                var newString:String = linkFinder.Process();
                 var imgURL:String = myXML.entry[i].link[1].@href;
                 _twitterUser = myXML.entry[i].author.uri;
                 
                
               //bmpフォーマットのアイコン画像を使っている人も少なくないため、Flashで使えるファイルの拡張子かどうかを判別
                var extention:String = imgURL.substr( -4);
                extention = extention.toLowerCase();
                if (extention != ".jpg" && extention != ".gif" && extention != ".png") {
                imgURL = "http://s.twimg.com/a/1254440757/images/default_profile_mini.png";
                }
                imgURL = encodeURI(imgURL);     
               //imgURL = imgURL.replace(/_normal\./, "_mini\.");
                var htmldata:String = "";
              //htmldata = "<a href='" + link + "' target='_blank'>";
                htmldata += "<img src='" + imgURL + "' width='48' height='48' checkPolicyFile='true' />";
                htmldata += "<b>" + authorName + "</b> " +  newString + "";
                
                myTextField = new TextField();
                sp = new Sprite();
                this.sp.mouseEnabled = true;
                sp.graphics.beginFill(0xDDFDDD);
                sp.graphics.drawRect(92 , 190, 48, 48);
                sp.z = 3000 - i * 200 + 25;
                sp.alpha = 0;
                myTextField.width = 300;
                myTextField.x = 2+80;
                myTextField.wordWrap = true;
                myTextField.background = true;
                myTextField.backgroundColor = 0x222222;
                myTextField.border = true;
                myTextField.selectable = true;
                myTextField.borderColor = 0x000000;
                myTextField.textColor = 0xFFFFFF;
                myTextField.htmlText = htmldata;
                myTextField.autoSize = "left";
                myTextField.y = 180;
                myTextField.z = 3000- i * 200 + 25;
                sp.name = String(_twitterUser);
                myTextField.filters = [new DropShadowFilter(2, 90, 0x666666, 3, 8, 8)];
               _resultStage.addChild(myTextField);
               _resultStage.addChild(sp);
                sp.addEventListener(MouseEvent.CLICK, onPicClick);
                sp.addEventListener(MouseEvent.ROLL_OVER, function(evt:Event):void { evt.currentTarget.alpha = 0.1; } );
                sp.addEventListener(MouseEvent.ROLL_OUT, function(evt:Event):void{evt.currentTarget.alpha = 0;});
         //myTextField.addEventListener(MouseEvent.CLICK, function():void{trace("twitter"+myTextField.htmlText )});
     }
           //_resultStage.addEventListener(MouseEvent.CLICK, onPicClick);
            this.transform.perspectiveProjection = new PerspectiveProjection();
            this.transform.perspectiveProjection.projectionCenter = new Point(stage.stageWidth / 2 -100, stage.stageHeight / 3);
        }
        
        private function onPicClick(e:Event):void
        {
            trace(e.currentTarget.name)
        
            
            var url:String = _twitterUser;
            var request:URLRequest = new URLRequest(e.currentTarget.name);
            try 
            {
                navigateToURL(request, "_blank");    
            }
            catch (e:Error)
            {
                trace ("Error visiting Twitter page");
            }
}
       private function onClickDown(event:MouseEvent):void {
            if (_t != null) {
                _t.stop();
            }
            btnUp.enabled = true;
        _num += 125;
        _t = BetweenAS3.tween(_resultStage, { z: -_num }, null, 1, Quint.easeOut);
            _t.onUpdate = onUpdate;
          if (_resultStage.z <= -3150) {
            _t.stop();
            btnDown.enabled = false;
            
            }else {
                _t.play();
                }
        }
        private function onClickUp(event:MouseEvent):void {
            if (_t != null) {
                _t.stop();
            }
        btnDown.enabled = true;
        _num -= 125;
        _t = BetweenAS3.tween(_resultStage, { z: -_num }, null, 1, Quint.easeOut);
        _t.onUpdate = onUpdate;
        
        if (_resultStage.z >= -225) {
            _t.stop();
            btnUp.enabled = false;
            
            }else {
                _t.play();
                }
         _t.play();
        }
        
        private function onUpdate():void {
            var n:int = _resultStage.numChildren;
            for (var i:int = 0; i < n; i++) {
                _resultStage.getChildAt(i).visible = (_resultStage.getChildAt(i).z + _resultStage.z > -4000);
            }
         }
    }
}
class FindURL
    {
        
        import flash.text.TextField
        
        private var _wholeThing:String;
        
        /**
         * Constructor
         * 
         * @param    textToProcess    FindURL requires text to be passed to it as a String
         * 
         */ 
        public function FindURL(textToProcess:String)
        {
            
            var regExp1:RegExp = new RegExp("(^|\\s+)((https?|ftp|news|)\\:\\/\\/[^\\s]*[^.,;''>\\s\\)\\]])" , "gi");
        
            if (regExp1.test(textToProcess))
            {
            _wholeThing = textToProcess.replace(regExp1 , " <a href='$2' TARGET='_blank'><font color='#979393'>$2</font></a> ");
        }
            else
            {
                _wholeThing = textToProcess;
            }
            
        }
        public function Process():String
        {
            
            return _wholeThing;
        }
        
    }