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: Flickr pipes

// forked from keiso's Flickr pipes
package
{
  import caurina.transitions.Tweener;
  import flash.display.Loader;
  import flash.display.LoaderInfo;
  import flash.display.Sprite;
  import flash.events.*;
  import flash.net.*;
  import flash.system.Security;
  import flash.system.LoaderContext;
  import flash.utils.escapeMultiByte;

   [SWF(width="464", height="464",backgroundColor="#000000",frameRate="30")]  
   
  public class Demo6 extends Sprite
  {
    private var query:String = "イチゴ";//検索キーワード
    private var numOfImage:uint = 36;
    private var URL:String = "http://pipes.yahooapis.com/pipes/pipe.run?_id=1FZD9tbQ3RGdxrAHbbsjiw&_render=rss&n=" + String(numOfImage) + "&q=" + escapeMultiByte(query);
    
    private var loader:URLLoader;
    private var imgWidth:uint = 77;
    private var imgHeight:uint = 77;
    private var imgOffset:uint = 2;
    private var xmlData:XML;
    private var media:Namespace = new Namespace("http://search.yahoo.com/mrss/");
    
    private var _loadingCircle:LoadingCircle;
    private var _imageCollection:RingCollection;
    
    private var _itemCount:Number = 0;
    private var _loadedCount:Number = 0;
  
    public function Demo6()
    {
      var req:URLRequest = new URLRequest(URL);
      loader = new URLLoader();
      loader.dataFormat = URLLoaderDataFormat.TEXT;
      
      req.method = "GET";
      req.url = URL;
      configureListeners(loader);
      
      try {
        loader.load(req);
            } catch (error:Error) {
               trace("Unable to load requested document.");
            }
      _imageCollection = new RingCollection();
      _loadingCircle = new LoadingCircle({color:0xFF0000});
      addChildAt(_loadingCircle, 0);
      _loadingCircle.x = stage.stageWidth / 2;
      _loadingCircle.y = stage.stageHeight / 2;

      Security.loadPolicyFile("http://farm1.static.flickr.com/crossdomain.xml");
      Security.loadPolicyFile("http://farm2.static.flickr.com/crossdomain.xml");
      Security.loadPolicyFile("http://farm3.static.flickr.com/crossdomain.xml");
      Security.loadPolicyFile("http://farm4.static.flickr.com/crossdomain.xml");
    }
    private function configureListeners(dispatcher:IEventDispatcher):void {
      dispatcher.addEventListener(Event.COMPLETE, completeHandler);
    }

    private function completeHandler(event:Event):void {
      var loader:URLLoader = URLLoader(event.target);
      xmlData = new XML(loader.data);
      
      default xml namespace = new Namespace("http://search.yahoo.com/mrss/");;
      for each(var element:Object in xmlData.channel.item){
        var imgURL:String = element.media::group.media::content.@url;
        var imgReq:URLRequest = new URLRequest(imgURL);
        var img:Loader = new Loader();
        img.contentLoaderInfo.addEventListener(Event.COMPLETE, img_completeHandler);
        img.load(imgReq, new LoaderContext(true));
        _itemCount++;
      }
    }
    
    private function img_completeHandler(event:Event):void
    {
      var loaderInfo:LoaderInfo = LoaderInfo(event.target);
      var img:Loader = loaderInfo.loader;
      var reflect:Reflect = new Reflect(img, { isCentering:true, scale:0.5 } );
      reflect.x = 0 - Math.round(reflect.width / 2);
      reflect.y = Math.round(stage.stageHeight / 2);
      addChildAt(reflect, 0);
      _imageCollection.push(reflect);
      if (_itemCount == ++_loadedCount) 
      {
        removeChild(_loadingCircle);
        fire();
      }
    }
    
    private function fire():void
    {
      var reflect:Reflect = Reflect(_imageCollection.next());
      reflect.x = -Math.round(reflect.width);
      reflect.alpha = 0.5;
      Tweener.addTween(reflect, {
        x:Math.round(stage.stageWidth / 2),
        alpha:1.0,
        onComplete:onFire, onCompleteParams:[reflect],
        transition:"easeoutexpo", time:0.5
      });  
    }
    
    private function onFire(target:Reflect):void
    {
      Tweener.addTween(target, {
        x:stage.stageWidth  + target.width,
        alpha:0.5,
        onComplete:fire,
        transition:"easeinexpo", time:0.5, delay:2
      });  
    }
    
    }
}
/**
 * image collection
 */
class RingCollection
{
  //---------------------------------------------------------------------
  //  properties
  //---------------------------------------------------------------------
  /** collection item count */
  public function get count():uint
  {
    return _list.length;
  }
  
  /** collection holder */
  private var _list:Array = [];
  
  /** current index */
  private var _currentIndex:int = -1;
  
  //---------------------------------------------------------------------
  //  method
  //---------------------------------------------------------------------
  /**
   * constructor
   * @param list
   */
  public function RingCollection(list:Array=null) 
  {
    if (!list) list = [];
    _list = list;
  }
  
  /**
   * pickup item at index
   * @param  index
   * @return
   */
  public function at(index:uint):*
  {
    return _list[index];
  }
  
  /**
   * push item
   * @param item
   */
  public function push(item:*):void
  {
    _list.push(item);
  }
  
  /**
   * get next item
   * @return *
   */
  public function next():*
  {
    _currentIndex++;
    if (_list.length <= _currentIndex) _currentIndex = 0;
    return _list[_currentIndex];
  }
  
  /**
   * get prev item
   * @return *
   */
  public function prev():*
  {
    _currentIndex--;
    if (_currentIndex < 0) _currentIndex = _list.length - 1;
    return _list[_currentIndex];
  }
  
  public function first():*
  {
    _currentIndex = 0;
    return _list[_currentIndex];
  }
  
  public function last():*
  {
    _currentIndex = _list.length - 1;
    return _list[_currentIndex];
  }
}

import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.GradientType;
import flash.display.IBitmapDrawable;
import flash.display.Shape;
import flash.display.Sprite;
import flash.geom.Matrix;
/**
 * コンストラクタの引数で受け取った表示オブジェクトを反射させた表示オブジェクトを含むSpriteを作成します
 */
class Reflect extends Sprite
{
  //---------------------------------------------------------------------
  //  properties
  //---------------------------------------------------------------------
  private static const DEFAULT_SCALE:Number = 0.3;
  private var _originalMatrix:Matrix;
  private var _target:DisplayObject;
  private var _scale:Number;
  private var _isCentering:Boolean;
  private var _base:Sprite;
  
  //---------------------------------------------------------------------
  //  method
  //---------------------------------------------------------------------
  /**
   * constructor
   * @param  target
   * @param  option
   */  
  public function Reflect(target:IBitmapDrawable, options:Object = null) 
  {
    _target = DisplayObject(target);
    _originalMatrix = _target.transform.matrix;
    _target.transform.matrix = new Matrix();
    if (options && options["scale"]) _scale = options["scale"];
    else _scale = DEFAULT_SCALE;
    if (options && options["isCentering"]) _isCentering = options["isCentering"];
    
    createMirror();
  }
  
  private function createMirror():void
  {
    var bitmapData:BitmapData = new BitmapData(_target.width, _target.height, false, 0xFF000000);
    var drawMatrix:Matrix = _target.transform.matrix;
    try
    {
      bitmapData.draw(_target);
    }
    catch (error:SecurityError)
    {
        trace(error.message);
      throw(new Error("can't create Mirror"));
      return;
    }
    var reflect:Bitmap = new Bitmap(bitmapData, "never", true);
    reflect.cacheAsBitmap = true;
    
    _target.transform.matrix = _originalMatrix;
    reflect.transform.matrix = _originalMatrix;
    reflect.scaleY *= -1;
    reflect.y = _target.height + reflect.height;
    
    // 反転画像にグラデーションマスクをかける
    var matrix:Matrix = new Matrix();
    matrix.createGradientBox(reflect.width, reflect.height, Math.PI / 2);
    var maskShape:Shape = new Shape();
    maskShape.graphics.beginGradientFill(GradientType.LINEAR, [0x000000, 0x000000], [_scale, 0.0], [0, 255*_scale], matrix);
    maskShape.graphics.drawRect(0, 0, reflect.width, reflect.height);
    maskShape.x = reflect.x;
    maskShape.y = _target.height;
    maskShape.cacheAsBitmap = true;
    
    //cacheAsBitmap = true;
    _base = new Sprite();
    _base.addChild(DisplayObject(_target));
    _base.addChild(maskShape);
    _base.addChild(reflect);
    reflect.mask = maskShape;
    if (_isCentering) 
    {
      _base.x = -Math.round(_target.width / 2);
      _base.y = -Math.round(_target.height / 2);
    }
    addChild(_base);
  }
}

import caurina.transitions.Tweener;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;

/**
 * simple loding circle
 */
class LoadingCircle extends Sprite
{
  // _____________________________________________________ Property
  private const DEFAULT_COLOR:uint = 0x000000;
  
  private const DEFAULT_RADIUS:Number = 20;
  
  private const DEFAULT_SIZE:Number = 4.5;
  
  private const DEFAULT_COUNT:uint = 10;
  
  /** color */
  private var _color:uint;
  
  /** radius */
  private var _radius:Number;
  
  /** per size */
  private var _size:Number;
  
  /** circle count */
  private var _count:uint;
  
  // _____________________________________________________ Method
  /**
   * constructor
   */
  public function LoadingCircle(initObject:Object = null) 
  {
    super();
    if (initObject && initObject.color) _color = initObject.color;
    else _color = DEFAULT_COLOR;
    if (initObject && initObject.radius) _radius = initObject.radius;
    else _radius = DEFAULT_RADIUS;
    if (initObject && initObject.size) _size = initObject.size;
    else _size = DEFAULT_SIZE;
    if (initObject && initObject.count) _count = initObject.count;
    else _count = DEFAULT_COUNT;
    draw();
    play();
  }
  
  /**
   * draw circle grapic
   */
  public function draw():void
  {
    var i:uint;
    var radian:Number;      
    graphics.clear();
    for (i= 0; i < _count; i++)
    {
      radian = Math.PI * 2 * (i / _count);
      graphics.beginFill(_color, (i+1) / _count);
      graphics.drawCircle(Math.cos(radian) * _radius, Math.sin(radian) * _radius, _size);
    }
  }
  
  /**
   * play rotate motion
   */
  public function play():void
  {
    visible = true;
    Tweener.addTween(this, { rotation:360, time:2, onComplete:play, transition:"easeOutSine", delay:0 } );
  }
  
  /**
   * stop rotate motion
   */
  public function stop():void
  {
    Tweener.removeTweens(this);
    visible = false;
  }
}