@@ -105,7 +105,18 @@ this.createjs = this.createjs || {};
105105 * can be overridden to provide custom formatting.
106106 *
107107 * Optionally, a resultFormatter can return a callback function in cases where the formatting needs to be
108- * asynchronous, such as creating a new image.
108+ * asynchronous, such as creating a new image. The callback function is passed 2 parameters, which are callbacks
109+ * to handle success and error conditions in the resultFormatter. Note that the resultFormatter method is
110+ * called in the current scope, as well as the success and error callbacks.
111+ *
112+ * <h4>Example asynchronous resultFormatter</h4>
113+ *
114+ * function _formatResult(loader) {
115+ * return function(success, error) {
116+ * if (errorCondition) { error(errorDetailEvent); }
117+ * success(result);
118+ * }
119+ * }
109120 * @property resultFormatter
110121 * @type {Function }
111122 * @default null
@@ -674,12 +685,11 @@ this.createjs = this.createjs || {};
674685 case "complete" :
675686 this . _rawResult = event . target . _response ;
676687 var result = this . resultFormatter && this . resultFormatter ( this ) ;
677- var _this = this ;
678688 if ( result instanceof Function ) {
679- result ( function ( result ) {
680- _this . _result = result ;
681- _this . _sendComplete ( ) ;
682- } ) ;
689+ result . call ( this ,
690+ createjs . proxy ( this . _resultFormatSuccess , this ) ,
691+ createjs . proxy ( this . _resultFormatFailed , this )
692+ ) ;
683693 } else {
684694 this . _result = result || this . _rawResult ;
685695 this . _sendComplete ( ) ;
@@ -703,6 +713,29 @@ this.createjs = this.createjs || {};
703713 }
704714 } ;
705715
716+ /**
717+ * The "success" callback passed to {{#crossLink "AbstractLoader/resultFormatter"}}{{/crossLink}} asynchronous
718+ * functions.
719+ * @method _resultFormatSuccess
720+ * @param {Object } result The formatted result
721+ * @private
722+ */
723+ p . _resultFormatSuccess = function ( result ) {
724+ this . _result = result ;
725+ this . _sendComplete ( ) ;
726+ } ;
727+
728+ /**
729+ * The "error" callback passed to {{#crossLink "AbstractLoader/resultFormatter"}}{{/crossLink}} asynchronous
730+ * functions.
731+ * @method _resultFormatSuccess
732+ * @param {Object } error The error event
733+ * @private
734+ */
735+ p . _resultFormatFailed = function ( event ) {
736+ this . _sendError ( event ) ;
737+ } ;
738+
706739 /**
707740 * @method buildPath
708741 * @protected
0 commit comments