0
我有一個代碼,它從xml繪製了一堆自定義的形狀...我想通過更改顏色使每個形狀可選/可選擇的對象,並改變backk所有其他顏色的東西改變時,但我的代碼壞了,但我沒有得到任何錯誤或任何東西,它只是不起作用。我的形狀不會改變顏色我不知道爲什麼
var graphicsShape
function drawLayer(layer){
for (var i =0; i < xmlDoc.getElementsByTagName("polygon").length; i++)
{
if (layer == xmlDoc.getElementsByTagName("polygon")[i].childNodes[0].attributes[4].value)
{ drawSegment(i);
}
}
}
// layer = index z
function drawSegment(a){
var vertexList = xmlDoc.getElementsByTagName("polygon")[a].childNodes;
var graphicsObject = new createjs.Graphics();
graphicsShape = new createjs.Shape(graphicsObject);
graphicsObject.setStrokeStyle(1);
graphicsObject.beginStroke(createjs.Graphics.getRGB(0,0,0));
graphicsObject.beginFill(createjs.Graphics.getRGB(255,0,0));
for(var i = 0; i < vertexList.length; i++){
graphicsObject.lineTo(vertexList[i].attributes[2].value, vertexList[i].attributes[3].value)
stage.addChild(graphicsShape);
}
segmentsArray.push(graphicsShape);
//createContainer(segmentsArray[i]);
}
function createArraysForSegments() {
for(var i=0; i <segmentsArray.length; i++){
segmentsData[i] = new Array;
}
}
function ColorChangeAddEventListener() {
for(var i = 0; i < segmentsArray.length; i++){
segmentsArray[i].addEventListener('click', colorChange(i));
}
}
function colorChange(index){
segmentsArray[index].graphics.beginFill('white');
stage.update();
}
我調用的函數以後 ColorChangeAddEventListener(); drawLayer(0); stage.update();
如果我鍵入segmentsArray [0] .alpha = 0.5;它適用於那種形狀,但是當我把它放在segmentsArray [0] .addEventsListener('click',function){segmentsArray [0] .alpha = 0.5;})時,它不起作用