Parser Class

Module: cc.AssetManager

Parse the downloaded file, it's a singleton, all member can be accessed with cc.assetManager.parser

Index

Methods
  • register Register custom handler if you want to change default behavior or extend parser to parse other format file
  • parse Use corresponding handler to parse file

Details

Methods

register

Register custom handler if you want to change default behavior or extend parser to parse other format file

meta description
Defined in cocos2d/core/asset-manager/parser.js:443
Parameters
  • type string | Object Extension likes '.jpg' or map likes {'.jpg': jpgHandler, '.png': pngHandler}
  • handler Function The corresponding handler
    • file File
    • options Object Some optional paramter
    • onComplete Function callback when finishing parsing
Examples
parser.register('.tga', (file, options, onComplete) => onComplete(null, null));
parser.register({'.tga': (file, options, onComplete) => onComplete(null, null), '.ext': (file, options, onComplete) => onComplete(null, null)});
parse

Use corresponding handler to parse file

meta description
Defined in cocos2d/core/asset-manager/parser.js:474
Parameters
  • id string The id of file
  • file Any File
  • type string The corresponding type of file, likes '.jpg'.
  • options Object Some optional paramters will be transferred to the corresponding handler.
  • onComplete Function callback when finishing downloading
    • err Error The occurred error, null indicetes success
    • contetnt The parsed file
Examples
downloader.downloadFile('test.jpg', {responseType: 'blob'}, null, (err, file) => {
     parser.parse('test.jpg', file, '.jpg', null, (err, img) => console.log(err));
});

results matching ""

    No results matching ""