EDIT: This got way too complicated, I will migrate this question to another question and put up my new code there! Please ignore the code on this because it is logically flawed. (Please vote to close the question as it makes no sense)
Hi,
I am initializing the following loops in my code. The code is written using mootools.
CANVAS.init({ canvasElement : 'canvas', interactive : true });
var itemlayer = CANVAS.layers.add({ id : 'items' });
for(var j = 0; j < 5; j++)
{
for(var i = 0; i < 5; i++)
{
itemlayer.add({
id : 'item-'+i + '-' + j,
x : 51 * i,
y : 51 * j,
w : 50,
h : 50,
state : 'normal',
interactive : true,
colors : { normal : '#f00', hover : '#00f' },
events : {
onDraw : function(ctx){
ctx.fillStyle = this.colors[this.state];
ctx.fillRect(this.x,this.y,this.w,this.h);
this.setDims(this.x,this.y,this.w,this.h);
}
}
});
}
}
/* object that hold the information whether a certain object
* is in animation right now or not. This is used to prevent
* multiple Cmorph instances working on the same item
* */
var locked= {};
for(i= 0; i<6; i++)
for(j= 0; j<6; j++)
{
itemid = 'item-'+i+'-'+j;
itemid : false,
}
//then once I have done that
//animate all items with the function given below
function animate()
{
for(i=0;i<6;i++)
for(j=0;j<6;j++)
{
itemid = 'item-'+i+'-'+j;
if(locked.itemid)return; //guess even this will return errors!
locked.itemid = true;
var item = CANVAS.layers.get('myLayer').get(itemid);
new Cmorph(item,{
duration : 1000,
transition : 'bounce:out',
onComplete : function()
{
locked.itemid = false;
}
}
).morph({
y : (item.y == 50?375:50),
scale : (item.scale == 1?2:1)
});
}
}
CANVAS.addThread(new Thread({
id : 'myThread',
onExec : function(){
CANVAS.clear().draw();
}
}));
Is my syntax correct and will all the id’s get locked or am I going to have errors. Also if I am making a mistake, could you please correct me. I know this is a very dumb doubt, but please bear with me! thanks 🙂
I am not exactly sure what you mean by “locking”, but the syntax has some errors. This is how i would do this:
It constructs an array of strings, holding your item-string.
You cannot use normal code statements inside of JSON (
{}). You need to create it, and populate it afterwards, if you need this (more complex) behaviour.EDIT: According to your clarification: I can spot a single syntax error at the end: Your inner
for-loop is missing his closing}. On the other hand, i do not know mootools in detail, so there might be mootools-related problems left.