A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [F8] Loops for enabling buttons

  1. #1
    light11.ca habboguy's Avatar
    Join Date
    Apr 2002
    Posts
    384

    [F8] Loops for enabling buttons

    Alright im making a risk game and i have it set up so far so that you can drag little army pieces and put them on a country which then makes the power of that country go up.

    when i try and use a for loop, it only enables the last button it goes through (army5).

    If i use an onEnterFrame loop, its too slow.

    I need a loop that will loop all the buttons (may get around 100) and make them all available to be used with onRelease. This is what i have so far.

    "arm" is for the army pieces.
    "armm" is for the country movie clips.
    PHP Code:
    for (arm=1arm<=5arm++) {
        
    armm = eval("army"+arm);
        
    trace(armm);
        
    armm.onPress = function() {
            
    this.startDrag();
        };
        
    armm.onRelease = function() {
            
    this.stopDrag();
            for (
    i=1i<=6i++) {
                if (
    this.hitTest(eval("m"+i))) {
                    
    armm._x = eval("m"+i+"._x");
                    
    armm._y = eval("m"+i+"._y");
                    
    = eval("m"+i);
                    
    y.+= 1;
                }
            }
        };


  2. #2
    supernoob
    Join Date
    Jun 2003
    Location
    Indonesia
    Posts
    41
    I'd do it like this:
    Code:
    var movedArmy:MovieClip;
    function init() {
    	for (i=1; i<=5; i++) {
    		this["arm"+i].onPress = function() {
    			this.startDrag();
    			movedArmy = this;
    		};
    		this["arm"+i].onRelease = function() {
    			this.stopDrag();
    			handleDrop();
    		};
    	}
    	
    }
    function handleDrop() {
    	for(i=1;i<=3;i++){
    		if(this["country"+i].hitTest(movedArmy)){
    			trace("hit by "+movedArmy);
    			//code
    		}
    	}
    }
    
    init();
    [anggie bratadinata]

  3. #3
    light11.ca habboguy's Avatar
    Join Date
    Apr 2002
    Posts
    384
    thank you so much!

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