View Full Version : break problem
werehunt
November 21st, 2009, 02:36 AM
obvioulsy i dont know how to use break :D
this break doesnt termainte my for loop, it skips to the else below it, why is it doing that?
if (_mcArr.length == 0) {
Mouse.hide();
} else {
for (var i:int = 0; i < _mcArr.length; i++) {
if (_mcArr[i].hitTestPoint( _stage.mouseX, _stage.mouseY, true)) {
break;
} else {
//it skips here
Mouse.hide();
}
}
}
Shaedo
November 21st, 2009, 03:32 AM
well it should be ok. Lets say you have the following code:
var _mcArr:Array = new Array(0,1,2,3,4,5);
for (var i:int = 0; i < _mcArr.length; i++)
{
if (_mcArr[i] == 1)
{
trace ('breaking');
break;
}
else
{
trace ('else statement');
}
}
you will get the output
else statement
breaking
it loops through the 'for' loop and checks your 'if' statement. Of course the first thing in my example _mcArr array is '0' so it switches to the 'else' statement. If something in your _mcArr array does not pass your 'if' statement it will go to your 'else' statement which I imagine is happening to you.
For the second loop through the 'for' loop, the 'if' statement is true, so it outputs the trace and then breaks the 'for' loop.
makes sense? if not then put trace statements in both your 'if' and 'else' statments and it should be clearer.
Luck,
S.
EDIT
http://help.adobe.com/en_US/AS3LCR/Flash_10.0/statements.html#break
werehunt
November 21st, 2009, 04:02 AM
yeah, you are right, i rewrote the code, the code was wrong, i should have checked if it touches any item in the array and then run mouse.hide.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.