Html5 canvas removeAllChildren在createjs中不工作

Html5 canvas removeAllChildren在createjs中不工作,html5-canvas,createjs,Html5 Canvas,Createjs,我试图更改createjs中的位图图像,并希望在单击“重置”按钮时删除容器中的所有子对象。但是removeAllChildren在我身上不起作用 function drawPhoneImage() { stage = new createjs.Stage('canvas'); container = new createjs.Container(); phone = new createjs.Bitmap(phoneImg); phone.x = 268; phone.y

我试图更改createjs中的位图图像,并希望在单击“重置”按钮时删除容器中的所有子对象。但是removeAllChildren在我身上不起作用

function drawPhoneImage() {
  stage = new createjs.Stage('canvas');
  container = new createjs.Container();

  phone = new createjs.Bitmap(phoneImg);
  phone.x = 268;
  phone.y = 64;

  stage.addChild(container);
  container.addChild(phone);
  stage.update();

  phone.addEventListener("click", function() {
    console.log('phone clicked');
    createjs.Ticker.addEventListener("tick", movePhoneImage);
  });
}

function movePhoneImage(event) {
  phone.x -=10;

  if(phone.x <  156) { 
    phone.x =156;
    showPhoneSnap();
  }
  stage.update(event);
}
起初,removeAllChildren在容器的第一个子容器中工作,但当我在容器中添加另一个位图后尝试重置阶段时..removeAllChildren()不工作

function resetStage() {
  container.removeAllChildren();
  stage.update();
} 
我很难解决这个问题,谢谢所有能帮忙的人

确保“snapImg”是已加载的图像

snap = new createjs.Bitmap(snapImg);
var image = new Image();
image.src = "path";
image.onload = showPhoneSnap;
function showPhoneSnap() {
    //This will ensure that the image is ready.
    var bmp = new createjs.Bitmap(this);
    ...
    stage.update();
}
问题在于加载映像时没有更新阶段

snap = new createjs.Bitmap(snapImg);
var image = new Image();
image.src = "path";
image.onload = showPhoneSnap;
function showPhoneSnap() {
    //This will ensure that the image is ready.
    var bmp = new createjs.Bitmap(this);
    ...
    stage.update();
}

如何调用
resetStage()
?调用期间是否记录了任何错误?$('#reset')。单击(function(){resetStage();});显示时没有错误。一个假设是,范围可能是错误的,但在这种情况下,它将引发
阶段
容器
未定义
的错误。