내 배열에서 3 개의 이미지를 반복하여 스테이지에 추가하려고합니다 (easelJS 사용). 나는 그것을 배치하고 싶다. 배열의 이미지에 액세스하려고하면 x가 정의되지 않았 음을 알리는 오류가 발생합니다. easeljs 비트 맵의 x 변수에 액세스 할 수없는 이유는 무엇입니까?왜 비트 맵의 x 변수에 액세스 할 수 없습니까? (javascript)
function displayPosters() {
getPosters(); //get all images and assign it to designated array
console.log(frontPosters);
console.log(frontPosters.length);
if(currentCat == Category.HOME) { //if current category is HOME
for(var i = 0; i < frontPosters.length; i++) { //loop through posters
frontPosters[i].x = 40; //set x position for testing, also where error occurs
stage.addChild(frontPosters[i]); //add poster to stage
}
}
}
여기에 이미지를로드하여 frontPosters arrray로 푸시하기위한 코드가 있습니다. 실제로 아닌 값 (배열 자체 일명) 배열 오브젝트 반복하고 있기 때문에 사용 for(poster in frontPosters)
var frontPosters = new Array(3);
function getPosters() {
var games = new Image(); //create 3 images
var apps = new Image();
var aboutme = new Image();
games.onload = function() { //add image to frontImages array on load
var gamesPost = new createjs.Bitmap(games);
frontPosters[0] = gamesPost;
};
apps.onload = function() {
var appPost = new createjs.Bitmap(apps);
frontPosters[1] = appPost;
};
aboutme.onload = function() {
var amPost = new createjs.Bitmap(aboutme);
frontPosters[2] = amPost;
};
games.src = "images/assets/posters/games_poster.jpg";
apps.src = "images/assets/posters/apps_poster.jpg";
aboutme.src = "images/assets/posters/aboutme_poster.jpg";
}
문제는 "frontPosters [0] .x = 40;"입니다. 또는 이와 비슷한 오류가 여전히 발생합니다. – kag359six
그렇다면 'frontposters'에 포함 된 것이 무엇인지 모르는 한 당신을 도울 수는 없습니다. 'for' 루프 앞에'console.log (frontPosters);'를 추가하고, dev-tools (또는 firebug) 콘솔을 열어 배열에 포함 된 것을 볼 수 있습니다. 그것이 항목을 명확하게하지 않으면 원래 게시물에 추가합니다. 최소한 우리가 처리하는 대상을 알 것입니다. – iMoses
나는 그것이 3 개의 이미지를 포함한다고 말했다. 하지만 도움이된다면 그 이미지를 다루는 코드를 게시 할 것입니다. – kag359six