|
-
Senior Member
infinite for loop problem
Code:
package
{
import flash.geom.*;
import flash.display.*;
import flash.events.*;
public class Main extends MovieClip
{
var sp:Sprite = new Sprite();
public function Main()
{ addChild(sp);
drawPoints(20,20);
}
public function drawPoints(sx=0,sy=0)
{
var ptArr = [0,0,10,0,10,10,10,20,60,20,60,10,60,0,70,0];
sp.graphics.lineStyle(1,0x00ff00);
sp.graphics.moveTo(sx,sy);
for(var i=2;i<ptArr.length;i+2) <--PROBLEM PORTION
{
sp.graphics.lineTo(ptArr[i]+sx,ptArr[i+1]+sy);
trace(i);
}
}
}
}
When I run the code, it seems to run eternally and freeze, however in the for loop, if I replace i+2 with i++ and put in another i++ inside, the problem doesn't occur.....any idea what's going on?
If you like me, add me to your friends list  .
PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!
My Arcade My Blog
Add me on twitter: 
-
Senior Member
When using i+2, you aren't actually assigning the value (while i++ translates to i = i + 1).
So try instead i += 2 or i = i + 2.
-
Senior Member
If you like me, add me to your friends list  .
PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!
My Arcade My Blog
Add me on twitter: 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|