// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class HelloWord extends cc.Component {

    @property(cc.Label)
    label: cc.Label = null;

    @property
    text: string = 'hello';

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    start () {


    //     cc.assetManager.pipeline.insert((task, done)=>{
    //         for (var i = 0; i < task.input.length; i++) {
    //             task.input[i].content = null;
    //         }
    //         task.output = task.input;
    //         done;
    //     }, 1);
    //    cc.resources.load("HelloWorld",null,null,(err,asset:cc.SpriteFrame)=>{

    //    })
        // cc.assetManager.loadAny( {path: 'HelloWorld', bundle: 'resources'},(finished: number, total: number, item: cc.AssetManager.RequestItem) =>{
        //     cc.log(finished,total,item)
        // },(err,res)=>{

        // })

        cc.resources.load("HelloWorld",cc.SpriteFrame,null,(err,asset:cc.SpriteFrame)=>{
            cc.log(asset)
        
            let aa = new cc.Node()
            let spr = aa.addComponent(cc.Sprite)
            spr.spriteFrame = asset
            console.log("aa.refCount:",asset.refCount)
            asset.addRef()
            this.node.addChild(aa)
            aa.destroy()
            this.scheduleOnce(()=>{
                console.log("aa.refCount:",asset.refCount)
                cc.director.loadScene("secScene")
            })
        })

        // cc.assetManager.loadBundle('kefu', function (err, bundle) {
        //     if (err) {
        //         return console.error(err);
        //     }
        //     let bundleA = cc.assetManager.getBundle('kefu');
        //     bundleA.loadDir("111",cc.SpriteFrame,(finished, total, item)=>{
        //         console.log(finished,total,item)
        //     },(err,res)=>{
        //         var bundle = cc.assetManager.getBundle('kefu');
        //         bundle.releaseAll();
        //         cc.assetManager.removeBundle(bundle);

        //     })
        //     console.log(bundleA);
        // });
        // // cc.director.loadScene()
        // // cc.assetManager.getBundle('st');
        // var bundle = cc.assetManager.getBundle('kefu');
        // bundle.releaseAll();
        // cc.assetManager.removeBundle(bundle);

    }

    // update (dt) {}
}
