@@ -48,6 +48,9 @@ var File = new Class({
4848 this . xhrSettings = MergeXHRSettings ( this . xhrSettings , GetFastValue ( fileConfig , 'xhrSettings' , { } ) ) ;
4949 }
5050
51+ // The LoaderPlugin instance that is loading this file
52+ this . loader = null ;
53+
5154 this . xhrLoader = null ;
5255
5356 this . state = CONST . FILE_PENDING ;
@@ -70,8 +73,6 @@ var File = new Class({
7073 // Multipart file? (i.e. an atlas and its json together)
7174 this . linkFile = undefined ;
7275 this . linkType = '' ;
73-
74- this . callback = null ;
7576 } ,
7677
7778 resetXHR : function ( )
@@ -81,20 +82,54 @@ var File = new Class({
8182 this . xhrLoader . onprogress = undefined ;
8283 } ,
8384
84- // Called when the Image loads
85- // ProgressEvent
85+ // Called by the Loader, starts the actual file downloading.
86+ // During the load the methods onLoad, onProgress, etc are called based on the XHR events.
87+ load : function ( loader )
88+ {
89+ this . loader = loader ;
90+
91+ if ( this . state === CONST . FILE_POPULATED )
92+ {
93+ this . onComplete ( ) ;
94+
95+ loader . nextFile ( this ) ;
96+ }
97+ else
98+ {
99+ this . src = GetURL ( this , loader . baseURL ) ;
100+
101+ if ( this . src . indexOf ( 'data:' ) === 0 )
102+ {
103+ console . log ( 'Local data URI' ) ;
104+ }
105+ else
106+ {
107+ this . xhrLoader = XHRLoader ( this , loader . xhr ) ;
108+ }
109+ }
110+ } ,
111+
112+ // Called when the file loads, is sent a DOM ProgressEvent
86113 onLoad : function ( event )
87114 {
88115 this . resetXHR ( ) ;
89116
90- this . callback ( this , true ) ;
117+ if ( event . target && event . target . status !== 200 )
118+ {
119+ this . loader . nextFile ( this , false ) ;
120+ }
121+ else
122+ {
123+ this . loader . nextFile ( this , true ) ;
124+ }
91125 } ,
92126
127+ // Called when the file errors, is sent a DOM ProgressEvent
93128 onError : function ( event )
94129 {
95130 this . resetXHR ( ) ;
96131
97- this . callback ( this , false ) ;
132+ this . loader . nextFile ( this , false ) ;
98133 } ,
99134
100135 onProgress : function ( event )
@@ -105,11 +140,14 @@ var File = new Class({
105140 this . bytesTotal = event . total ;
106141
107142 this . percentComplete = Math . min ( ( this . bytesLoaded / this . bytesTotal ) , 1 ) ;
108- }
109143
110- // console.log(this.percentComplete + '% (' + this.bytesLoaded + ' bytes)');
144+ // console.log(this.percentComplete + '% (' + this.bytesLoaded + ' bytes)');
145+ this . loader . emit ( 'fileprogress' , this , this . percentComplete ) ;
146+ }
111147 } ,
112148
149+ // Usually overriden by the FileTypes and is called by Loader.finishedLoading.
150+ // The callback is Loader.processUpdate
113151 onProcess : function ( callback )
114152 {
115153 this . state = CONST . FILE_PROCESSING ;
@@ -139,25 +177,6 @@ var File = new Class({
139177 {
140178 this . state = CONST . FILE_COMPLETE ;
141179 }
142- } ,
143-
144- // Called by the Loader, starts the actual file downloading
145- load : function ( callback , baseURL , globalXHR )
146- {
147- if ( baseURL === undefined ) { baseURL = '' ; }
148-
149- this . callback = callback ;
150-
151- this . src = GetURL ( this , baseURL ) ;
152-
153- if ( this . src . indexOf ( 'data:' ) === 0 )
154- {
155- console . log ( 'Local data URI' ) ;
156- }
157- else
158- {
159- this . xhrLoader = XHRLoader ( this , globalXHR ) ;
160- }
161180 }
162181
163182} ) ;
0 commit comments