answered question
0
Votes
Votes
1
Answer
Answer
M$0.25
How can I do multiple ORd IF comparisons of dynamic variables in Actionscript 2?
I am having issues w/ the following code.
First I create a number of dynamic variables in the movieclip based on content in an XML file in a function called AssignBits(), which works great.
AssignBits = function(xmlObject){
var curr_node;
for (var i=0; i < xmlObject.childNodes.length; i++) {
curr_node = xmlObject.childNodes[i];
if (curr_node.nodeName == "green"){
grnBitCount = grnBitCount + 1;
this["grnBit"+grnBitCount] = parseInt(curr_node.attributes.bit,10) - 1;
} else if (curr_node.nodeName == "yellow"){
ylwBitCount = ylwBitCount + 1;
this["ylwBit"+ylwBitCount] = parseInt(curr_node.attributes.bit,10) - 1;
} else if (curr_node.nodeName == "red"){
redBitCount = redBitCount + 1;
this["redBit"+redBitCount] = parseInt(curr_node.attributes.bit,10) - 1;
}
}
}
I then have a listenerevent defined to watch for changes in a array in my root movie, which I then you an IF statement to determine, which "bit" in the table changed. When I had static variables for the bits, I checked it like the following.
if ((_root.outputTable[redBitNum] != bitState>>0 & 0x1) ||
(_root.outputTable[ylwBitNum1] != bitState>>1 & 0x1) || (_root.outputTable[ylwBitNum2] != bitState>>2 & 0x1) ||
(_root.outputTable[ylwBitNum3] != bitState>>3 & 0x1) || (_root.outputTable[ylwBitNum4] != bitState>>4 & 0x1) ||
(_root.outputTable[ylwBitNum5] != bitState>>5 & 0x1) || (_root.outputTable[ylwBitNum6] != bitState>>6 & 0x1) ||
(_root.outputTable[ylwBitNum7] != bitState>>7 & 0x1) || (_root.outputTable[ylwBitNum8] != bitState>>8 & 0x1) ||
(_root.outputTable[ylwBitNum9] != bitState>>9 & 0x1) || (_root.outputTable[ylwBitNum10] != bitState>>10 & 0x1) ||
(_root.outputTable[ylwBitNum11] != bitState>>11 & 0x1) || (_root.outputTable[ylwBitNum12] != bitState>>12 & 0x1) ||
(_root.outputTable[ylwBitNum13] != bitState>>13 & 0x1) || (_root.outputTable[ylwBitNum14] != bitState>>14 & 0x1) ||
(_root.outputTable[grnBitNum1] != bitState>>15 & 0x1) || (_root.outputTable[grnBitNum2] != bitState>>16 & 0x1) ||
(_root.outputTable[grnBitNum3] != bitState>>17 & 0x1) || (_root.outputTable[grnBitNum4] != bitState>>18 & 0x1) ||
(_root.outputTable[grnBitNum5] != bitState>>19 & 0x1) || (_root.outputTable[grnBitNum6] != bitState>>20 & 0x1) ||
(_root.outputTable[grnBitNum7] != bitState>>21 & 0x1) || (_root.outputTable[grnBitNum8] != bitState>>22 & 0x1) ||
(_root.outputTable[grnBitNum9] != bitState>>23 & 0x1) || (_root.outputTable[grnBitNum10] != bitState>>24 & 0x1) ||
(_root.outputTable[grnBitNum11] != bitState>>25 & 0x1) || (_root.outputTable[grnBitNum12] != bitState>>26 & 0x1) ||
(_root.outputTable[grnBitNum13] != bitState>>27 & 0x1) || (_root.outputTable[grnBitNum14] != bitState>>28 & 0x1))
{
....
}
Now how would I perform the same IF w/ dynamic variables?
First I create a number of dynamic variables in the movieclip based on content in an XML file in a function called AssignBits(), which works great.
AssignBits = function(xmlObject){
var curr_node;
for (var i=0; i < xmlObject.childNodes.length; i++) {
curr_node = xmlObject.childNodes[i];
if (curr_node.nodeName == "green"){
grnBitCount = grnBitCount + 1;
this["grnBit"+grnBitCount] = parseInt(curr_node.attributes.bit,10) - 1;
} else if (curr_node.nodeName == "yellow"){
ylwBitCount = ylwBitCount + 1;
this["ylwBit"+ylwBitCount] = parseInt(curr_node.attributes.bit,10) - 1;
} else if (curr_node.nodeName == "red"){
redBitCount = redBitCount + 1;
this["redBit"+redBitCount] = parseInt(curr_node.attributes.bit,10) - 1;
}
}
}
I then have a listenerevent defined to watch for changes in a array in my root movie, which I then you an IF statement to determine, which "bit" in the table changed. When I had static variables for the bits, I checked it like the following.
if ((_root.outputTable[redBitNum] != bitState>>0 & 0x1) ||
(_root.outputTable[ylwBitNum1] != bitState>>1 & 0x1) || (_root.outputTable[ylwBitNum2] != bitState>>2 & 0x1) ||
(_root.outputTable[ylwBitNum3] != bitState>>3 & 0x1) || (_root.outputTable[ylwBitNum4] != bitState>>4 & 0x1) ||
(_root.outputTable[ylwBitNum5] != bitState>>5 & 0x1) || (_root.outputTable[ylwBitNum6] != bitState>>6 & 0x1) ||
(_root.outputTable[ylwBitNum7] != bitState>>7 & 0x1) || (_root.outputTable[ylwBitNum8] != bitState>>8 & 0x1) ||
(_root.outputTable[ylwBitNum9] != bitState>>9 & 0x1) || (_root.outputTable[ylwBitNum10] != bitState>>10 & 0x1) ||
(_root.outputTable[ylwBitNum11] != bitState>>11 & 0x1) || (_root.outputTable[ylwBitNum12] != bitState>>12 & 0x1) ||
(_root.outputTable[ylwBitNum13] != bitState>>13 & 0x1) || (_root.outputTable[ylwBitNum14] != bitState>>14 & 0x1) ||
(_root.outputTable[grnBitNum1] != bitState>>15 & 0x1) || (_root.outputTable[grnBitNum2] != bitState>>16 & 0x1) ||
(_root.outputTable[grnBitNum3] != bitState>>17 & 0x1) || (_root.outputTable[grnBitNum4] != bitState>>18 & 0x1) ||
(_root.outputTable[grnBitNum5] != bitState>>19 & 0x1) || (_root.outputTable[grnBitNum6] != bitState>>20 & 0x1) ||
(_root.outputTable[grnBitNum7] != bitState>>21 & 0x1) || (_root.outputTable[grnBitNum8] != bitState>>22 & 0x1) ||
(_root.outputTable[grnBitNum9] != bitState>>23 & 0x1) || (_root.outputTable[grnBitNum10] != bitState>>24 & 0x1) ||
(_root.outputTable[grnBitNum11] != bitState>>25 & 0x1) || (_root.outputTable[grnBitNum12] != bitState>>26 & 0x1) ||
(_root.outputTable[grnBitNum13] != bitState>>27 & 0x1) || (_root.outputTable[grnBitNum14] != bitState>>28 & 0x1))
{
....
}
Now how would I perform the same IF w/ dynamic variables?
answers (1)
I don't know if I totally got it, but this question's been out here a while. What about this?
boolean bit_changed = false;
for (i=0; !bit_changed && i < grnBitCount; ++i) {
bit_changed = (this"grnBit"+redBitCount >> i & 0x1);
}
for (i=0; !bit_changed && i < ylwBitCount; ++i) {
bit_changed = (this"ylwBit"+redBitCount >> i & 0x1);
}
for (i=0; !bit_changed && i < redBitCount; ++i) {
bit_changed = (this"redBit"+redBitCount >> i & 0x1);
}
boolean bit_changed = false;
for (i=0; !bit_changed && i < grnBitCount; ++i) {
bit_changed = (this"grnBit"+redBitCount >> i & 0x1);
}
for (i=0; !bit_changed && i < ylwBitCount; ++i) {
bit_changed = (this"ylwBit"+redBitCount >> i & 0x1);
}
for (i=0; !bit_changed && i < redBitCount; ++i) {
bit_changed = (this"redBit"+redBitCount >> i & 0x1);
}
Related questions
140 characters left












