不工作我使用的是最新的kineticjs。(v.3.10) 這裏的問題是Layer.remove(Image);在Kinetic.js
我使用的是單一的功能將圖像發送到畫布這些都對點擊畫布外。 我正在使圖像拖動和所有.. 我也添加了刪除圖像功能雙擊。 當我雙擊任何圖像.. 最後添加的圖像被刪除,之後,如果我嘗試點擊一些其他圖像.. 我得到這個錯誤:TypeError:this.children [child.index]是undefined
這裏是一個小代碼:
使用此功能,使用AJAX
function loadajax(imgpath,imgid){
sources = {
yoda1 : imgpath,
};
loadImages(sources,initStage1);
};
來源函數來從另一個文件的路徑:----
function loadImages(sources, callback){
var images = {};
var loadedImages = 0;
var numImages = 0;
for (var src in sources) {
numImages++;
}
for (var src in sources) {
images[src] = new Image();
images[src].onload = function(){
if (++loadedImages >= numImages) {
callback(images);
}
};
images[src].src = sources[src];
}
}
下面是我使用刪除/拖放/等功能..
function initStage1(images){
yodaGroup1 = new Kinetic.Group({
x: 100,
y: 110,
draggable: true,
});
layery = new Kinetic.Layer();
layery.add(yodaGroup1);
stage.add(layery);
var yoda1 = new Kinetic.Image({
image: images.yoda1,
x: 0,
y: 0,
width: 100,
height: 120,
name:"image",
detectionType:"Pixel"
});
yodaGroup1.add(yoda1);
yodaGroup1.on("dragstart", function() {
yodaGroup1.moveToTop();
layery.draw();
});
yodaGroup1.on("dblclick dbltap", function() {
layery.remove(yodaGroup1);
layery.draw();
});
yodaGroup1.on("dragend", function() {
layery.draw();
yoda1.saveImageData();
});
addAnchor(yodaGroup1,0, 0, "topLeft");
addAnchor(yodaGroup1, 100, 0, "topRight");
addAnchor(yodaGroup1, 100, 120, "bottomRight");
addAnchor(yodaGroup1, 0, 120, "bottomLeft");
stage.draw();
yoda1.saveImageData();
}
現按這個功能 我應該能夠將圖像添加到畫布上(這是工作精) 應能對另一移動一個圖像,當我將它拖到(.ie.moveToTop功能)_Not工作 應該能去除雙擊()的圖像僅最新添加的圖像工作
請幫助
Tha NKS