2

我正在使用javascriptKinetic.

<script src="http://d3lp1msu2r81bx.cloudfront.net/kjs/js/lib/kinetic-v4.4.2.min.js"></script>

我需要Kinetic.Images()用不同的图像创建一个数组。这是我的代码。

var imagesRef = ["cNote.gif","dNote.gif","eNote.gif","fNote.gif","gNote.gif","aNote.gif","cNote.gif","cSharpdFlat.gif","dSharpeFlat.gif","fSharpgFlat.gif","gSharpaFlat.gif","aSharpbFlat.gif"];                                                                        
    var imageObjs=[] ;
    var imageObj;
    var images=[];
    var image;
    var imageX = 0;
    var stage = new Kinetic.Stage({
        container: 'container',
        width: 578,
        height: 200
      });
      var layer = new Kinetic.Layer();
  function drawImages(){
  for(i=0;i<11;i++){
    var imageObj = new Image();
    imageObjs[i] = imageObj;
    imageObjs[i].src= imagePath + imagesRef[i];

    alert(imageObjs[i].src);
    imageObjs[i].onload = function(){
      alert("imageOnload has been called");
    var image = new Kinetic.Image({
           x:imageX,
           y:0,
           image:imageObjs[i],
           width:75,
           height:75,
           stroke:'black',
           strokeWidth:1,
           strokeEnabled:true
        });

        alert("image has been created");
        alert(image.getImage());
    images[i] = image;
    layer.add(images[i]);
    imageX += 75;
    layer.draw();
    }

  }
   }
stage.add(layer);

</script>

 <input type="button" onclick="drawImages();"id="submit" value="submit" />

单击按钮时,它应该加载图像。但相反,只有中风kinetic.image被加载

所以我看到的是一排矩形,里面没有像它应该的图像。在imageObjs[i].src警报“图像已创建”之前,每次迭代循环时都会触发警报。当我尝试时,alert(image.getImage())我变得不确定。

4

1 回答 1

1

我认为这可能是因为您没有定义 variable imagePath

于 2013-04-16T04:37:53.580 回答