/**
 * VERSION: 0.9
 * DATE: 2010-08-09
 * AS3
 * UPDATES AND DOCUMENTATION AT: http://www.GreenSock.com/LoaderMax/
 **/
package com.greensock.loading.data.core {
    import com.greensock.loading.core.LoaderCore;
    
    import flash.display.DisplayObject;
/**
 * Facilitates code hinting and data type enforcement for the <code>vars</code> object that's passed into the 
 * constructor of various loaders in the LoaderMax system. There is no reason to use this class directly - see
 * docs for the vars classes that extend LoaderCoreVars like XMLLoaderVars, SWFLoaderVars, LoaderMaxVars, etc.<br /><br />
 * 
 * <b>Copyright 2010, GreenSock. All rights reserved.</b> This work is subject to the terms in <a href="http://www.greensock.com/terms_of_use.html">http://www.greensock.com/terms_of_use.html</a> or for corporate Club GreenSock members, the software agreement that was issued with the corporate membership.
 * 
 * @author Jack Doyle, jack@greensock.com
 */     
    dynamic public class LoaderCoreVars {
        /** @private **/
        private static var _vars:Array = ["name",
                                          "onComplete",
                                          "onProgress",
                                          "onFail",
                                          "requireWithRoot",
                                          "autoDispose",
                                          "onOpen",
                                          "onCancel",
                                          "onError",
                                          "onIOError",
                                          "onHTTPStatus"];
        
        /** A name that is used to identify the loader instance. This name can be fed to the <code>LoaderMax.getLoader()</code> or <code>LoaderMax.getContent()</code> methods or traced at any time. Each loader's name should be unique. If you don't define one, a unique name will be created automatically, like "loader21". **/
        public var name:String;
        /** A handler function for <code>LoaderEvent.COMPLETE</code> events which are dispatched when the loader has finished loading successfully. Make sure your onComplete function accepts a single parameter of type <code>LoaderEvent</code> (<code>com.greensock.events.LoaderEvent</code>). **/
        public var onComplete:Function;
        /** A handler function for <code>LoaderEvent.PROGRESS</code> events which are dispatched whenever the <code>bytesLoaded</code> changes. Make sure your onProgress function accepts a single parameter of type <code>LoaderEvent</code> (<code>com.greensock.events.LoaderEvent</code>). You can use the LoaderEvent's <code>target.progress</code> to get the loader's progress value or use its <code>target.bytesLoaded</code> and <code>target.bytesTotal</code>.**/
        public var onProgress:Function;
        /** A handler function for <code>LoaderEvent.FAIL</code> events which are dispatched whenever the loader fails and its <code>status</code> changes to <code>LoaderStatus.FAILED</code>. Make sure your onFail function accepts a single parameter of type <code>LoaderEvent</code> (<code>com.greensock.events.LoaderEvent</code>). **/
        public var onFail:Function;
        /** LoaderMax supports <i>subloading</i>, where an object can be factored into a parent's loading progress. If you want LoaderMax to require this loader as part of its parent SWFLoader's progress, you must set the <code>requireWithRoot</code> property to your swf's <code>root</code>. For example, <code>vars.requireWithRoot = this.root;</code>. **/
        public var requireWithRoot:DisplayObject;
        /** When <code>autoDispose</code> is <code>true</code>, the loader will be disposed immediately after it completes (it calls the <code>dispose()</code> method internally after dispatching its <code>COMPLETE</code> event). This will remove any listeners that were defined in the vars object (like onComplete, onProgress, onError, onInit). Once a loader is disposed, it can no longer be found with <code>LoaderMax.getLoader()</code> or <code>LoaderMax.getContent()</code> - it is essentially destroyed but its content is not unloaded (you must call <code>unload()</code> or <code>dispose(true)</code> to unload its content). The default <code>autoDispose</code> value is <code>false</code>.**/
        public var autoDispose:Boolean;
        /** A handler function for <code>LoaderEvent.OPEN</code> events which are dispatched when the loader begins loading. Make sure your onOpen function accepts a single parameter of type <code>LoaderEvent</code> (<code>com.greensock.events.LoaderEvent</code>).**/
        public var onOpen:Function;
        /** A handler function for <code>LoaderEvent.CANCEL</code> events which are dispatched when loading is aborted due to either a failure or because another loader was prioritized or <code>cancel()</code> was manually called. Make sure your onCancel function accepts a single parameter of type <code>LoaderEvent</code> (<code>com.greensock.events.LoaderEvent</code>). **/
        public var onCancel:Function;
        /** A handler function for <code>LoaderEvent.ERROR</code> events which are dispatched whenever the loader experiences an error (typically an IO_ERROR or SECURITY_ERROR). An error doesn't necessarily mean the loader failed, however - to listen for when a loader fails, use the <code>onFail</code> special property. Make sure your onError function accepts a single parameter of type <code>LoaderEvent</code> (<code>com.greensock.events.LoaderEvent</code>). **/
        public var onError:Function;
        /** A handler function for <code>LoaderEvent.IO_ERROR</code> events which will also call the onError handler, so you can use that as more of a catch-all whereas <code>onIOError</code> is specifically for LoaderEvent.IO_ERROR events. Make sure your onIOError function accepts a single parameter of type <code>LoaderEvent</code> (<code>com.greensock.events.LoaderEvent</code>).</li> **/
        public var onIOError:Function;
        /** A handler function for <code>LoaderEvent.HTTP_STATUS</code> events. Make sure your onHTTPStatus function accepts a single parameter of type <code>LoaderEvent</code> (<code>com.greensock.events.LoaderEvent</code>). You can determine the httpStatus code using the LoaderEvent's <code>target.httpStatus</code> (LoaderItems keep track of their <code>httpStatus</code> when possible, although certain environments prevent Flash from getting httpStatus information).**/
        public var onHTTPStatus:Function;
        
        /** @private **/
        protected var _props:Array;
        
        
        /**
         * Constructor
         * @private
         */
        public function LoaderCoreVars(name:String="", 
                                       onComplete:Function=null,
                                       onProgress:Function=null,
                                       onFail:Function=null,
                                       requireWithRoot:DisplayObject=null) {
            _props = _vars.slice();
            this.name = name;
            this.onComplete = onComplete;
            this.onProgress = onProgress;
            this.onFail = onFail;
            this.requireWithRoot = requireWithRoot;
        }
        
        /** @private **/
        protected function _cloneProps(vars:LoaderCoreVars):LoaderCoreVars {
            for each (var p:String in _props) {
                vars[p] = this[p];
            }
            for (p in this) { //now do the dynamic props.
                vars[p] = this[p];
            }
            return vars;
        }
        
    }
}