You could also set a var on the button that tracks it's own content.

function buttonBehavior():Void  { 
        for (var i=1; i < 8; i++) {
                //do tmpMC = _root["mb_"+i]; just once per loop  
                //to save processing 
                var tmpMC:MovieClip = _root["mb_"+i]; 
                // add a var to the mc that tracks it's content
                tmpMC.href = "section_"+i+".swf";
                
                tmpMC.onRollOver = function() { 
                        this.gotoAndPlay("over"); 
                } 
                tmpMC.onRollOut = function() { 
                        this.gotoAndPlay("out"); 
                } 
                tmpMC.onRelease = function() { 
                        this.gotoAndPlay("display_frame"); 
                        loadMovie(this.href, "load_target");
                }
        }
}
buttonBehavior();



-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Keith
Reinfeld
Sent: Thursday, March 30, 2006 5:11 PM
To: 'Flashcoders mailing list'
Subject: RE: [Flashcoders] Counter in function assigned inside a for
loop

Try this Alex, 
 
 
function buttonBehavior():Void  { 
        for (var i=1; i < 8; i++) {
                //do tmpMC = _root["mb_"+i]; just once per loop  
                //to save processing 
                var tmpMC:MovieClip = _root["mb_"+i]; 
                tmpMC.onRollOver = function() { 
                        this.gotoAndPlay("over"); 
                } 
                tmpMC.onRollOut = function() { 
                        this.gotoAndPlay("out"); 
                } 
                tmpMC.onRelease = function() { 
                        this.gotoAndPlay("display_frame"); 
                        //replace i with this._name.substr(3,4)  
                        //to get the right value from the current button

                        var loadMe:String =
"section_"+this._name.substr(3,4)+".swf"; 
                        loadMovie(loadMe, "load_target");
                }
        }
}
buttonBehavior(); 
 
 
-Keith

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Alejandro
Diaz
Sent: Thursday, March 30, 2006 9:22 AM
To: Flashcoders mailing list
Subject: [Flashcoders] Counter in function assigned inside a for loop

Heya guys,

I am assigning the button behaviors to a set of movieclips through a
for loop, however, I am coming up against something where I know what
is happening, but don't know how to fix it.

Basically, inside that for loop I assign each of the button behaviors
as a function but I don't know how to evaluate the counter in the
function, rather than having it just literally written into it.
instead of "section_"+ _root.i  being  section_1, section_2, etc...it
is literally written in each of the buttons as "section_"+_root.i  and
so each button has exactly the same code and all go to the last
section (last value of i) when clicked.

How can I have it so that each function has the proper code it in? is
this even the proper way to go about this? Is there a way to 'force'
the evaluation of that counter in that function when it is being
assigned to the MC?



code:

function buttonBehavior ():Void  {
for (_root.i=1;_root.i<8;_root.i++) {
        _root["mb_"+_root.i].onRollOver = function() {
               this.gotoAndPlay("over");
        }
        _root["mb_"+_root.i].onRollOut = function() {
               this.gotoAndPlay("out");
        }
        _root["mb_"+_root.i].onRelease = function() {
               _root.gotoAndPlay("display_frame");
               loadMovie("section_"+_root.i+".swf", "load_target");
        }


}
}

(btw, I added the _root. to each of the i's so that the function could
'see'
it.

thanks in advance!
-Alex
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to