LoadingItems Class

Extends CallbacksInvoker

Module: cc

LoadingItems is the queue of items which can flow them into the loading pipeline.</br> Please don't construct it directly, use LoadingItems.create instead, because we use an internal pool to recycle the queues.</br> It hold a map of items, each entry in the map is a url to object key value pair.</br> Each item always contains the following property:</br>

  • id: The identification of the item, usually it's identical to url</br>
  • url: The url </br>
  • type: The type, it's the extension name of the url by default, could be specified manually too.</br>
  • error: The error happened in pipeline will be stored in this property.</br>
  • content: The content processed by the pipeline, the final result will also be stored in this property.</br>
  • complete: The flag indicate whether the item is completed by the pipeline.</br>
  • states: An object stores the states of each pipe the item go through, the state can be: Pipeline.ItemState.WORKING | Pipeline.ItemState.ERROR | Pipeline.ItemState.COMPLETE</br> </br> Item can hold other custom properties.</br> Each LoadingItems object will be destroyed for recycle after onComplete callback</br> So please don't hold its reference for later usage, you can copy properties in it though.

Index

Properties
  • map Object The map of all items.
  • completed Object The map of completed items.
  • totalCount Number Total count of all items.
  • completedCount Number Total count of completed items.
  • active Boolean Activated or not.
Methods
  • onProgress This is a callback which will be invoked while an item flow out the pipeline. You can pass the callback function in LoadingItems.create or set it later.
  • onComplete This is a callback which will be invoked while all items is completed, You can pass the callback function in LoadingItems.create or set it later.
  • create The constructor function of LoadingItems, this will use recycled LoadingItems in the internal pool if possible. You can pass onProgress and onComplete callbacks to visualize the loading process.
  • getQueue Retrieve the LoadingItems queue object for an item.
  • itemComplete Complete an item in the LoadingItems queue, please do not call this method unless you know what's happening.
  • append Add urls to the LoadingItems queue.
  • allComplete Complete a LoadingItems queue, please do not call this method unless you know what's happening.
  • isCompleted Check whether all items are completed.
  • isItemCompleted Check whether an item is completed.
  • exists Check whether an item exists.
  • getContent Returns the content of an internal item.
  • getError Returns the error of an internal item.
  • addListener Add a listener for an item, the callback will be invoked when the item is completed.
  • hasListener Check if the specified key has any registered callback. </br> If a callback is also specified, it will only return true if the callback is registered.
  • remove Removes a listener. </br> It will only remove when key, callback, target all match correctly.
  • removeAllListeners Removes all callbacks registered in a certain event type or all callbacks registered with a certain target.
  • itemComplete Complete an item in the LoadingItems queue, please do not call this method unless you know what's happening.
  • destroy Destroy the LoadingItems queue, the queue object won't be garbage collected, it will be recycled, so every after destroy is not reliable.
  • invoke
  • add
  • has Check if the specified key has any registered callback. If a callback is also specified, it will only return true if the callback is registered.
  • removeAll Removes all callbacks registered in a certain event type or all callbacks registered with a certain target

Details

Properties

map

The map of all items.

meta description
Type Object
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/load-pipeline/loading-items.js:211
completed

The map of completed items.

meta description
Type Object
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/load-pipeline/loading-items.js:219
totalCount

Total count of all items.

meta description
Type Number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/load-pipeline/loading-items.js:227
completedCount

Total count of completed items.

meta description
Type Number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/load-pipeline/loading-items.js:235
active

Activated or not.

meta description
Type Boolean
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/load-pipeline/loading-items.js:243

Methods

onProgress

This is a callback which will be invoked while an item flow out the pipeline. You can pass the callback function in LoadingItems.create or set it later.

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/load-pipeline/loading-items.js:178
Parameters
  • completedCount Number The number of the items that are already completed.
  • totalCount Number The total number of the items.
  • item Object The latest item which flow out the pipeline.
Examples
loadingItems.onProgress = function (completedCount, totalCount, item) {
     var progress = (100 * completedCount / totalCount).toFixed(2);
     cc.log(progress + '%');
 }
onComplete

This is a callback which will be invoked while all items is completed, You can pass the callback function in LoadingItems.create or set it later.

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/load-pipeline/loading-items.js:194
Parameters
  • errors Array All errored urls will be stored in this array, if no error happened, then it will be null
  • items LoadingItems All items.
Examples
loadingItems.onComplete = function (errors, items) {
     if (error)
         cc.log('Completed with ' + errors.length + ' errors');
     else
         cc.log('Completed ' + items.totalCount + ' items');
 }
create

The constructor function of LoadingItems, this will use recycled LoadingItems in the internal pool if possible. You can pass onProgress and onComplete callbacks to visualize the loading process.

meta description
Returns LoadingItems
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/load-pipeline/loading-items.js:291
Parameters
  • pipeline Pipeline The pipeline to process the queue.
  • urlList Array The items array.
  • onProgress Function The progression callback, refer to LoadingItems.onProgress
  • onComplete Function The completion callback, refer to LoadingItems.onComplete
Examples
LoadingItems.create(cc.loader, ['a.png', 'b.plist'], function (completedCount, totalCount, item) {
     var progress = (100 * completedCount / totalCount).toFixed(2);
     cc.log(progress + '%');
 }, function (errors, items) {
     if (errors) {
         for (var i = 0; i < errors.length; ++i) {
             cc.log('Error url: ' + errors[i] + ', error: ' + items.getError(errors[i]));
         }
     }
     else {
         var result_a = items.getContent('a.png');
         // ...
     }
 })
getQueue

Retrieve the LoadingItems queue object for an item.

meta description
Returns LoadingItems
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/load-pipeline/loading-items.js:358
Parameters
  • item Object The item to query
itemComplete

Complete an item in the LoadingItems queue, please do not call this method unless you know what's happening.

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/load-pipeline/loading-items.js:370
Parameters
  • item Object The item which has completed
append

Add urls to the LoadingItems queue.

meta description
Returns Array
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/load-pipeline/loading-items.js:438
Parameters
  • urlList Array The url list to be appended, the url can be object or string
allComplete

Complete a LoadingItems queue, please do not call this method unless you know what's happening.

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/load-pipeline/loading-items.js:522
isCompleted

Check whether all items are completed.

meta description
Returns Boolean
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/load-pipeline/loading-items.js:534
isItemCompleted

Check whether an item is completed.

meta description
Returns Boolean
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/load-pipeline/loading-items.js:544
Parameters
exists

Check whether an item exists.

meta description
Returns Boolean
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/load-pipeline/loading-items.js:555
Parameters
getContent

Returns the content of an internal item.

meta description
Returns Object
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/load-pipeline/loading-items.js:566
Parameters
getError

Returns the error of an internal item.

meta description
Returns Object
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/load-pipeline/loading-items.js:588
Parameters
addListener

Add a listener for an item, the callback will be invoked when the item is completed.

meta description
Returns Boolean
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/load-pipeline/loading-items.js:609
Parameters
hasListener

Check if the specified key has any registered callback. </br> If a callback is also specified, it will only return true if the callback is registered.

meta description
Returns Boolean
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/load-pipeline/loading-items.js:620
Parameters
remove

Removes a listener. </br> It will only remove when key, callback, target all match correctly.

meta description
Returns Boolean
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/load-pipeline/loading-items.js:635
Parameters
removeAllListeners

Removes all callbacks registered in a certain event type or all callbacks registered with a certain target.

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/load-pipeline/loading-items.js:650
Parameters
  • key String | Object The event key to be removed or the target to be removed
itemComplete

Complete an item in the LoadingItems queue, please do not call this method unless you know what's happening.

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/load-pipeline/loading-items.js:682
Parameters
destroy

Destroy the LoadingItems queue, the queue object won't be garbage collected, it will be recycled, so every after destroy is not reliable.

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/load-pipeline/loading-items.js:722
invoke
meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/callbacks-invoker.js:229
Parameters
  • key String
  • p1 Any
  • p2 Any
  • p3 Any
  • p4 Any
  • p5 Any
add
meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/callbacks-invoker.js:96
Parameters
has

Check if the specified key has any registered callback. If a callback is also specified, it will only return true if the callback is registered.

meta description
Returns Boolean
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/callbacks-invoker.js:111
Parameters
removeAll

Removes all callbacks registered in a certain event type or all callbacks registered with a certain target

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/callbacks-invoker.js:147
Parameters
  • keyOrTarget String | Object The event key to be removed or the target to be removed

results matching ""

    No results matching ""