roemraw
08-07-2010, 08:59 PM
Hi, I am new to this site. I am not that new at AS, but I am definitly no pro.
I think the best way to describe my problem is to just show the code, so here goes:
var o = MovieClip.prototype;
var n:Number = 6;
var shift:Number = 0;
o.onRelease = function() {
for (i=1; i<(n); i++) {
mc = "_level0.MC"+i;
trace(mc)
trace(this)
if (this == mc) {
trace("hi")
shift = i;
}
}
}
Then when I click on a movieclip I get the following from the trace commands:
_level0.MC1
_level0.MC2
_level0.MC2
_level0.MC2
_level0.MC3
_level0.MC2
_level0.MC4
_level0.MC2
_level0.MC5
_level0.MC2
This shows that it correctly performs the trace commands in the fo-loop, the trace(mc) and trace(this).
As you can see
this == _level0.MC2
and the mc is being looped over and at one point it is also equal to "_level0.MC2"
My question is, why does the if-statement not recognize this correctly and respond by tracing:"hi" ?
The basic I dea is I have movieclips named MCi for i = 1 to n.
And I want to be able to track on which one I clicked by it returning me the i from their name.
So to say if I click on MC4 I want it to return the number 4 to me and when I click on MC98 I want it to return 98 to me.
Thanks in advance!
I think the best way to describe my problem is to just show the code, so here goes:
var o = MovieClip.prototype;
var n:Number = 6;
var shift:Number = 0;
o.onRelease = function() {
for (i=1; i<(n); i++) {
mc = "_level0.MC"+i;
trace(mc)
trace(this)
if (this == mc) {
trace("hi")
shift = i;
}
}
}
Then when I click on a movieclip I get the following from the trace commands:
_level0.MC1
_level0.MC2
_level0.MC2
_level0.MC2
_level0.MC3
_level0.MC2
_level0.MC4
_level0.MC2
_level0.MC5
_level0.MC2
This shows that it correctly performs the trace commands in the fo-loop, the trace(mc) and trace(this).
As you can see
this == _level0.MC2
and the mc is being looped over and at one point it is also equal to "_level0.MC2"
My question is, why does the if-statement not recognize this correctly and respond by tracing:"hi" ?
The basic I dea is I have movieclips named MCi for i = 1 to n.
And I want to be able to track on which one I clicked by it returning me the i from their name.
So to say if I click on MC4 I want it to return the number 4 to me and when I click on MC98 I want it to return 98 to me.
Thanks in advance!