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

resize

Get Adobe Flash player
by megane_bomb1 01 Jun 2011
/**
 * Copyright megane_bomb1 ( http://wonderfl.net/user/megane_bomb1 )
 * GNU General Public License, v3 ( http://www.gnu.org/licenses/quick-guide-gplv3.html )
 * Downloaded from: http://wonderfl.net/c/tfGT
 */

// forked from megane_bomb1's add bottom
// forked from megane_bomb1's img view

package {
    import flash.display.*;
    import flash.net.*;
    import flash.events.*;
    import flash.system.*;
    import flash.text.*; 
    import com.demonsters.debugger.MonsterDebugger;
    import caurina.transitions.Tweener;
    import caurina.transitions.properties.FilterShortcuts;   
    
    [SWF(backgroundColor = "0")]
    public class Main extends Sprite {
        private var scale:Number;
        private var index:int = 0;
        private var msg:TextField = new TextField();        
           
        //sprite
        private var navi:Sprite = new Sprite();
        private var container:Sprite = new Sprite(); 
        private var frame_count:int = 0;
        //private var width_s:Number = 1;
        private var stage_size:int = 465;
        private var flag:int = 0;
                            
        //class
        public var xml:XmlLoad = new XmlLoad();
        public var img:ImgView = new ImgView();
        public var btn:Button = new Button();

        //コンストラクタ         
        public function Main():void {
          stage.addEventListener( Event.RESIZE,  resizeH);
          MonsterDebugger.initialize(stage); 
          FilterShortcuts.init(); 
          btn.addEventListener("button_read",button_view);  
          xml.addEventListener("myEvent",loop);  
          xml.addEventListener("fall",fall);            
          btn.addEventListener("search",search);
          setStage();
          xml.url_str = "http://api.flickr.com/services/rest?api_key=d66685810fb12432a61842b076228d2e&method=flickr.photos.search&tags=flower&size=medium"
          xml.loadxml();
          btn.view();
  
          //sprite 順番
          stage.addChild(container);         
          stage.addChild(navi);
        }
        
        private function setStage():void {
           stage.quality = "BEST";
           stage.addEventListener( Event.RESIZE,  resizeH);
           stage.scaleMode = StageScaleMode.NO_SCALE;
           stage.align     = StageAlign.TOP_LEFT;
           Hoge.stage = stage;     
        }
        
        //100フレエームごとに呼び出す
        private function time(event:Event):void{
             frame_count +=1;
             var count:int = 100 * img.width_s * 0.8;
             if(frame_count % count == 0){
                 loop(event);
             }
        }
        
        //変更された比率を格納する(リサイズ時)  
        private function resizeH(event:Event):void{
             MonsterDebugger.trace(this,img.width_s);
             scale = stage.stageWidth / stage_size ;
             stage_size = stage.stageWidth;
             
             for(var i:int = container.numChildren; i > 0; i-- ){
                  var s:Sprite = new Sprite();
                  s = Sprite(container.getChildAt(i));
                  s.scaleX = scale;
                  s.scaleY = scale;
             }

        }
            
        private function search(event:Event):void{
            xml.text = event.target.search_text.text;
            xml.url_str = "http://api.flickr.com/services/rest?api_key=d66685810fb12432a61842b076228d2e&method=flickr.photos.search&tags="+ event.target.search_text.text + "&size=medium";
            xml.loadxml();
        }
        private function fall(event:Event):void{
            if(xml.text == "no tag"){
                stage.removeEventListener( Event.ENTER_FRAME, time );
            }
            
            var format:TextFormat = new TextFormat(); 
            format.color = 0xFFFFFF; 
            format.font = "Verdana"; 
            format.size = 20 * (stage.stageWidth/465); 
            format.align = TextFormatAlign.CENTER;
            msg.defaultTextFormat = format;
            msg.width = stage.stageWidth;
            msg.height = 25 + (20 * (stage.stageWidth/465));
            msg.y = -100;
            msg.text = xml.text;
            navi.addChild(msg);
            Tweener.addTween(msg,{y:stage.stageHeight,onComplete:remove_text,time:3,transition:"easeOutBounce"});     
        }
        
        private function remove_text():void{
            navi.removeChild(msg);
        }
        private function button_view(event:Event):void{
            navi.addChild(btn.tf);
            navi.addChild(btn.button);
            navi.addChild(btn.search_text);
        }
        
        
 
        //----------------------------------------------------
        //画像まわす
        //----------------------------------------------------
        private function loop(event:Event):void{

           if( xml.imageUrl_arr.length == index){
                index = 0;
           }    
           img = new ImgView();
           img.addEventListener("sprite",addimg);  
           img.index = index;
           
           img.width_s = (stage.stageWidth/465) * 0.7;
           if(img.width_s < 1){
               img.width_s = 1;
           }
           
           img.imageUrl_arr =  xml.imageUrl_arr;                  
           img.img_addchild();
           index = index + 1;
        }
        
        private function addimg(event:Event):void{
            event.target.removeEventListener("sprite",addimg);
            container.addChild(event.target.sprite);
            event.target.sprite.addEventListener( Event.ENTER_FRAME, img_down );
            stage.addEventListener( Event.ENTER_FRAME, time );
        }

        
        private function img_down(event:Event):void{
            event.target.y += 2;
 
            if(event.target.y >= stage.stageHeight){
                 var sprite:Sprite = Sprite(event.target);
                 container.removeChild(sprite);
                 event.target.removeEventListener(Event.ENTER_FRAME, img_down );
            }
        }

    }
}

import flash.ui.ContextMenuItem;
import com.demonsters.debugger.MonsterDebugger;
import caurina.transitions.Tweener;
import caurina.transitions.properties.FilterShortcuts;
import flash.filters.BlurFilter;
import flash.events.*;
    
class ImgView extends EventDispatcher {  
        public var sprite:Sprite;
        public var index:int;
        public var width_s:Number;
        
        public var imageUrl_arr:Array;   
        private var userID:String;
        private var ID:String;
        private var load_img:Loader;

        //画像loop
        public function img_addchild():void{
            var url_str:String;
            var url_img:URLRequest;
            url_str = imageUrl_arr[index].url;
            url_img = new URLRequest(url_str);
            var context:LoaderContext = new LoaderContext(true);  
            load_img = new Loader();  
            load_img.load(url_img,context);
            load_img.contentLoaderInfo.addEventListener( Event.COMPLETE , img_create ,false, 0, true);
            load_img.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOError,false, 0, true);
        }
        
        //画像生成
        public function img_create(event:Event):void{
             var my_blur:BlurFilter = new BlurFilter();
             load_img.contentLoaderInfo.removeEventListener( Event.COMPLETE , img_create);
             userID = imageUrl_arr[index].userID;
             ID = imageUrl_arr[index].id;

             //bitmapをspriteに!(大切)
             sprite = new Sprite();
             Bitmap(event.target.content).smoothing = true;
             sprite.addChild(event.target.content);
             
             //MouseEvent系
             sprite.addEventListener(MouseEvent.CLICK,jump);
             sprite.addEventListener(MouseEvent.ROLL_OVER,roll_over);
             sprite.addEventListener(MouseEvent.ROLL_OUT,roll_out);
             sprite.addEventListener(Event.REMOVED_FROM_STAGE,removeFunc);
             
             //ramdom
             sprite.x = Math.random()* Hoge.stage.stageWidth;           
             sprite.scaleX = sprite.scaleY = ((3 + (Math.random() * 5)) / 10) * width_s;
             sprite.y = 0 - sprite.height;
             
             var blur:int = 8 - (sprite.scaleX * 10);               
             my_blur.blurX = my_blur.blurY = blur;    // 水平方向のぼかし量
             my_blur.quality = 1;    // ぼかしの実行回数
             sprite.filters = [my_blur];
             dispatchEvent(new Event("sprite"));
        }
        
        private function removeFunc(event:Event):void{
            var sprite:Sprite = Sprite(event.target);
            sprite.removeEventListener(MouseEvent.CLICK,jump);
            sprite.removeEventListener(MouseEvent.ROLL_OVER,roll_over);
            sprite.removeEventListener(MouseEvent.ROLL_OUT,roll_out);
            sprite.removeEventListener(Event.REMOVED_FROM_STAGE,removeFunc);
        }
        //マウスイベント系   
        public function jump(event:Event):void{
            var url:URLRequest = new URLRequest("http://www.flickr.com/photos/" + imageUrl_arr[index].userID + "/" + imageUrl_arr[index].id );
            navigateToURL (url);
        }
        public function roll_over(event:Event):void{
            event.target.alpha = 0.7;
        }
        public function roll_out(event:Event):void{
            event.target.alpha = 1;
        }
        //IOError
        private function onIOError(event:Event):void{
             load_img.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);
        }

}


import flash.display.Stage;
class Hoge {
    public static var stage:Stage;
}
    

import flash.display.*;
import flash.net.*;
import flash.events.*;
import flash.system.*;
import com.demonsters.debugger.MonsterDebugger;

//URL渡すだけで良いように変更する
class XmlLoad extends EventDispatcher {
    public var imageUrl_arr:Array = new Array();
    public var url_str:String;
    private var xmlloader:URLLoader = new URLLoader();  
    public var text:String = "";
    
    public function loadxml():void{
        var url:URLRequest = new URLRequest(url_str);
        xmlloader = new URLLoader(url);
        xmlloader.load(url);
        xmlloader.addEventListener (Event.COMPLETE,get_imgURL);
    }


    public function get_imgURL( event:Event ):void {
         xmlloader.removeEventListener (Event.COMPLETE,get_imgURL);
         var length:int = 0;
         //XMLDATA抽出
         var xml : XML =  XML(xmlloader.data);
         var xmlList:XMLList = xml.photos.photo;
         
         length = xmlList.length();
         imageUrl_arr = [];
          if (length == 0) {
                text = "no tag";
                dispatchEvent(new Event("fall"));   
          }else{
            if(text == ""){
               text = "searching";
            }
            dispatchEvent(new Event("fall"));
            
            for(var i:int=0;i<length;i++){
                    var obj:Object = new Object();
                    var farm:String = xmlList[i].@farm;
                    var server:String = xmlList[i].@server;
                    var id:String = xmlList[i].@id;
                    var secret:String = xmlList[i].@secret;
                    var title:String = xmlList[i].@title;
                    var userID:String = xmlList[i].@owner;
    
                    var img_url:String = "http://farm" + farm + ".static.flickr.com/" + server + "/" + id + "_" + secret + "_m" +".jpg"; 
                    obj.url = img_url;
                    obj.title = title;
                    obj.userID = userID;
                    obj.id = id;
                               
                    imageUrl_arr.push(obj);
             }
             dispatchEvent(new Event("myEvent"));
          }
    }
}

import flash.text.*; 
import flash.events.*;
import com.demonsters.debugger.MonsterDebugger;

class Button extends EventDispatcher{
       public var search_text:TextField = new TextField();  
       public var tf:TextField =  new TextField();
       public var button : SimpleButton = new SimpleButton();
             
       public function view():void {
            //text
            var format:TextFormat = new TextFormat(); 
            format.color = "0xFFFFFF"; 
            format.size = 10; 
            format.align = TextFormatAlign.LEFT;
            tf.defaultTextFormat = format;
            tf.x = 10;
            tf.y = 5;
            tf.width = 100;
            tf.text = "Please input tag name!";            
            tf.mouseEnabled = false; //これ大切!マウスイベントを受け取らないように設定  
            
            //bottom            
            button.upState = makeRoundRect(0xffaa2b);
            button.overState = makeRoundRect(0xd58000);
            button.downState = makeRoundRect(0x553300);
            button.hitTestState = button.upState;
            button.addEventListener(MouseEvent.CLICK,search,false, 0, true);
            button.y = 25;
            button.x = 110;
            button.width = 40;
            
            //textfield
            search_text.addEventListener(KeyboardEvent.KEY_DOWN,push_enter,false, 0, true);
            search_text.background = true;
            search_text.width = 90;
            search_text.height = 20;
            search_text.y = 25;
            search_text.x = 10;
            search_text.type = "input";
            search_text.setSelection(0, 0);  
            dispatchEvent(new Event("button_read"));
          }
          
        //ボタン用グラフィック作成
        private function makeRoundRect(color:uint):Sprite{
            var s:Sprite = new Sprite();
            s.graphics.beginFill(color);
            s.graphics.drawRoundRect(0, 0, 100, 20, 15);
            s.graphics.endFill();
            s.alpha = 1;
            return s;
        }
        
        private function search(event:Event):void{
            if(search_text.text != ""){
                dispatchEvent(new Event("search"));     
            }
        }
        private function push_enter(event:KeyboardEvent):void{
             if(search_text.text != ""){
                 if(event.keyCode === 13){
                    dispatchEvent(new Event("search"));     
                }
             }
        }
}