Uncaught InvalidStateError:尝试使用不可用或不再可用的对象

问题描述 投票:0回答:1
Uncaught InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable. 

在这行代码中它发生:

var nodeIconImg = new Image();
                var nodeIcon = new Kinetic.Image({
                  image: nodeIconImg,
                  width: 30,
                  height: 30,
                  cornerRadius: radius
                });
            if(node.main_photo == 'no_photo.png')
            {
                var url = '<?= URL::to(''); ?>/img/' + node.main_photo;
                nodeIconImg.src = url;
            }

我使用kinetic js,字符串是正确的,图像文件存在,但在我分配src后发生错误,无法搞清楚,我也试过这个:

var url = escape('<?= URL::to(''); ?>/img/' + node.main_photo);

但它没有帮助,任何想法?

什么意思是这个错误?我该怎么做才能解决这个问题?

javascript php image canvas kineticjs
1个回答
0
投票

在创建Kinetic.Image对象之前,您必须等到图像加载。

var img = new Image();
img.onload = function() {
    var image = new Kinetic.Image({
       image : img
    });
}
img.src = 'url';

但是:Kua zxsw指出

© www.soinside.com 2019 - 2024. All rights reserved.