A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Can you put: _root.mc.onPress = function(){ inside a FOR { loop?

Threaded View

  1. #1
    Running Plodding & Limping SpockBert's Avatar
    Join Date
    Jun 2002
    Location
    London
    Posts
    593

    Can you put: _root.mc.onPress = function(){ inside a FOR { loop?

    Hi trying to do something really simple here but its not working properly. Using Flash 8.

    I have 3 movieclips (to be turned into buttons) on the main stage, instances named: "charm1", "charm2" and "charm3". On the main timeline, I have this code. Using a for loop I'm trying to assign a bit of code to each movieclip when its clicked on:
    Code:
    for (i = 1; i < 4; i++){
    
        trace ("i value:" + i);		
        // displays, "i value:1", "i value:2", "i value:3" like it should
    		
        _root["charm" + i].onPress = function(){
    
            trace ("i value:" + i);
            //displays "i value:4" for all 3 buttons, makes no sense!
    
        };
    
    }
    
    

    Why is my value for i, being incremented? Can anyone help, are there certain bits of code that aren't allowed inside a For loop?

    Cheers
    Si
    Last edited by SpockBert; 07-03-2009 at 11:51 AM. Reason: Missed out Flash version.

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