A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Flash Infinate Loop! Solution?

  1. #1
    -
    Join Date
    Feb 2006
    Posts
    74

    Flash Infinate Loop! Solution?

    Hi, I have a function called RandomLocation() that i call from a button and it chooses 6locations on the left side of the screen and then i want it to call 6locations on the right of the screen. The Locations are preset in an array.

    Below is the code for the function but when go through the do while once it reaches the end it freezes. Can any one see whats wrong with it?

    I have attached the full application fla as well


    Code:
    //Value either 6 or 11
    Max = 6;
    //Value either 0 or 6
    Min = 0;
    
    function RandomLocation(){
    //J Stops after its run 6 times
    	if (j <6){
    		//Flag to check that random number has already been picked
    		var myVar:Number = 0; 
    		//Repeat untill you find a random number that has not been picked.
    		do { 
    			i = Math.floor(Math.random()*(Max-Min))+Min;
    			// This checks if random number number has already been chosen
    			if (myArr[i] == 0){
    				trace("myVar: " + myVar+ " Radn="+i + " myArr[i]:" + myArr[i]); 
    				myArr[i] = 1;
    				//Set to any value that is not 0 to exit loop
    				myVar = 2;
    				j++;
    			}
    			trace(myVar+"Radn="+i); 
    			trace("X=" + pointer_mc._y + " Y=" +pointer_mc._y);
    			pointer_mc._x = TargetLocationArray[i][0];
        		pointer_mc._y = TargetLocationArray[i][1];
    		} 
    		while (myVar == 0);
    	}
    	else{
    	RunLeft();
    
    	}
    }
    function RunLeft(){
    	//Value either 6 or 11
    	Max = 11;
    	//Value either 0 or 6
    	Min = 6;
    	RandomLocation()
    }
    Attached Files Attached Files

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    do<>while will crash flash if it continuously evaluates to true - creating in infinite loop. Use a for loop instead if you know how many times you want to loop.

    gparis

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center