1  
     8   
     9  import com.sekati.display.CoreClip;
    10  import com.sekati.transitions.Mot;
    11  import com.sekati.utils.Delegate;
    12  import caurina.transitions.Tweener;
    13  
    14  
    17  class com.sekati.ui.Image extends CoreClip {
    18  
    19  	var img:MovieClip;
    20  	var box:MovieClip;
    21  	var spinner:MovieClip;
    22  
    23  	
    24  	private function Image() {
    25  	}
    26  
    27  	
    31  	private function configUI():Void {
    32  		_this.spinner._visible = false;
    33  	}
    34  
    35  	
    51  	public function load(uri:String, w:Number, h:Number, color:Number, color2:Number, alpha:Number, border:Boolean, cb:Function):Void {
    52  		_this.setup( w, h, color, color2, alpha, border );
    53  		_this.init( uri, cb );
    54  	}
    55  
    56  	
    70  	public function setup(w:Number, h:Number, color:Number, color2:Number, alpha:Number, border:Boolean):Void {
    71  		
    72  		if (_this.box != undefined) {
    73  			_this.box.removeMovieClip( );
    74  		}
    75  		if (_this.img != undefined) {
    76  			_this.img.removeMovieClip( );
    77  		}
    78  		_this.createEmptyMovieClip( "img", _this.getNextHighestDepth( ) );
    79  		
    80  		if (color) {
    81  			_this.createEmptyMovieClip( "box", _this.getNextHighestDepth( ) );
    82  			var c:Number = (color) ? color : 0xFFFFFF;
    83  			var a:Number = (alpha) ? alpha : 100;
    84  			var lw:Number = (border) ? 1 : 0;
    85  			var c2:Number = (color2) ? color2 : 0x000000;
    86  			
    87  			if (lw == 1) {
    88  				w += lw;
    89  				h += lw;
    90  				_this.img._x += lw;
    91  				_this.img._y += lw;
    92  			}
    93  			if (border) {
    94  				box.lineStyle( lw, c2, a );
    95  			}
    96  			box.beginFill( c, a );
    97  			box.moveTo( 0, 0 );
    98  			box.lineTo( w, 0 );
    99  			box.lineTo( w, h );
   100  			box.lineTo( 0, h );
   101  			box.endFill( );
   102  		}
   103  		
   104  		_this.spinner._x = int( (w / 2) );
   105  		_this.spinner._y = int( (h / 2) );
   106  		Tweener.addTween(_this.spinner, {_color:c2, time:0});
   107  	}
   108  
   109  	
   119  	public function init(uri:String, cb:Function):Void {
   120  		_this.img.unloadMovie( );
   121  		_this.img._alpha = 0;
   122  		_this.img.swapDepths( _this.getNextHighestDepth( ) );
   123  		_this.spinner.swapDepths( _this.getNextHighestDepth( ) );
   124  		_this.img.loadMovie( uri );
   125  		_this.spinner._visible = true;
   126  		_this.spinner._alpha = 100;
   127  		delete _this.spinner.onEnterFrame;
   128  		_this.spinner.onEnterFrame = function ():Void {
   129  			this._rotation -= 20;
   130  		};
   131  		_this.onEnterFrame = function ():Void {
   132  			var l:Number = _this.img.getBytesLoaded( );
   133  			var t:Number = _this.img.getBytesTotal( );
   134  			if (l >= t && t > 5) {
   135  				delete _this.onEnterFrame;
   136  				Tweener.removeTweens(_this.img);
   137  				Tweener.removeTweens(_this.spinner);
   138  				_this.img._alpha = 0;
   139  				_this.spinner._alpha = 100;
   140  				Tweener.addTween(_this.img, {_alpha:100, time:0.6, delay:0.1, transition:Mot.io.quad});
   141  				var spinCb:Function = function ():Void {
   142  					delete _this.spinner.onEnterFrame;
   143  					_this.spinner._visible = false;
   144  					_this.spinner._alpha = 100;
   145  				};
   146  				Tweener.addTween(_this.spinner, {_alpha:0, time:0.5, delay:0.3, transition:Mot.o.quint, onComplete:Delegate.create(_this, spinCb)});
   147  				if (cb) {
   148  					cb( );
   149  				}
   150  			}
   151  		};
   152  	}
   153  }