1  /**
     2   * com.sekati.load.GraphicLoader
     3   * @version 1.0.0
     4   * @author jason m horwitz | sekati.com | tendercreative.com
     5   * Copyright (C) 2007  jason m horwitz, Sekat LLC. All Rights Reserved.
     6   * Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
     7   */
     8  
     9  import com.sekati.load.Loader;
    10  import com.sekati.load.LoaderEvent;
    11  import com.sekati.utils.Delegate;
    12  /**
    13   * GraphicLoader
    14   */
    15  class com.sekati.load.GraphicLoader extends Loader {
    16  	private var _container:MovieClip;
    17  	private var _loader:MovieClipLoader;
    18  	private var _child:Object;
    19  	private var _o:Object;
    20  	public function GraphicLoader(container:MovieClip, url:String, reloads:Number) {
    21  		super( );
    22  		_child = Object( this );
    23  		
    24  		_rawURL = url;
    25  		_url = url;
    26  		_container = container;
    27  		_reloads = reloads;
    28  		
    29  		_loader = new MovieClipLoader( );
    30  		
    31  		_o = new Object( );
    32  		_o.onLoadInit = Delegate.create( this, onReady );
    33  		_o.onLoadError = Delegate.create( this, onError );
    34  		_o.onLoadProgress = Delegate.create( this, onProgress );		
    35  	}
    36  	public function load():Void {
    37  		_loader.addListener( _o );
    38  		_loader.loadClip( _url, _container );
    39  	}
    40  	public function unload():Void {
    41  		_loader.removeListener( _o );
    42  		_loader.unloadClip( _container );
    43  	}
    44  	private function onReady():Void {
    45  		_isReady = true;
    46  		onProgress( );	
    47  		_child.postLoad( );
    48  		broadcastEvent( LoadableEvents.onReady, this );
    49  	}
    50  	private function onError():Void {
    51  		if (_reloadCount++ >= _reloads || _reloads == null) {
    52  			broadcastEvent( LoaderEvent.onError, this );
    53  		} else {
    54  			broadcastEvent( LoaderEvent.onRetry, this );
    55  			reload( );
    56  		}
    57  	}
    58  }
    59