RE: [Flashcoders] Counter in function assigned inside a for loop
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.i8;_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 ___ Flashcoders@chattyfig.figleaf.com 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 ___ Flashcoders@chattyfig.figleaf.com 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 ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] Counter in function assigned inside a for loop
Hi Alex, here is an example that could help you and illustrate how to accomplish what you want var totalMovieClips:Number = 3; for ( var i = 0; i totalMovieClips; i ++ ) { _root['mc' + i].indexPos = i; _root[ 'mc' + i ].onRelease = function() { trace( 'mc' + this.indexPos + ' onRelease' ); } _root[ 'mc' + i ].onRollOver = function() { trace( 'mc' + this.indexPos + ' onRollOver' ); } _root[ 'mc' + i ].onRollOut = function() { trace( 'mc' + this.indexPos + ' onRollOut' ); } } On 3/30/06, Alejandro Diaz [EMAIL PROTECTED] wrote: 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.i8;_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 ___ Flashcoders@chattyfig.figleaf.com 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 ___ Flashcoders@chattyfig.figleaf.com 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
RE: [Flashcoders] Counter in function assigned inside a for loop
Ryan, Absolutely. That's how I've handled things on my homepage. The answer I suggested to Alex was an effort to stay on point with regard to his question. I would also recommend that he set up named functions outside his buttonBehavior function. It may not be necessary for his current project, but cleaner, and would make sufficiently generic functions available for other elements. function btnROver(){ this.gotoAndPlay(over); } function btnROut(){ this.gotoAndPlay(out); } function btnRelease(){ this.gotoAndPlay(display_frame); loadMovie(this.href, load_target); } 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; //assign button behavior functions tmpMC.onRollOver = btnROver; tmpMC.onRollOut = btnROut; tmpMC.onRelease = btnRelease; } } buttonBehavior(); -Keith http://home.mn.rr.com/keithreinfeld ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] Counter in function assigned inside a for loop
Thanks guys! I was cracking my head over this one (lack of sleep didn't help much), and of course, figures that right around the time I send this question I stop receiving all emails from Flashcoders (did it break for anyone else?). Anyways, great help and pointers and I will experiment with these tonight. Thank you all! -Alex ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] Counter in function assigned inside a for loop
oops I missed paste it complete... var totalMovieClips:Number = 3; for ( var i = 0; i totalMovieClips; i ++ ) { _root['mc' + i].indexPos = i; _root[ 'mc' + i ].onRelease = function() { trace( 'mc' + this.indexPos + ' onRelease' ); } _root[ 'mc' + i ].onRollOver = function() { trace( 'mc' + this.indexPos + ' onRollOver' ); } _root[ 'mc' + i ].onRollOut = function() { trace( 'mc' + this.indexPos + ' onRollOut' ); } } On 3/30/06, Ing. Mario Falomir [EMAIL PROTECTED] wrote: Hi Alex, here is an example that could help you and illustrate how to accomplish what you want var totalMovieClips:Number = 3; for ( var i = 0; i totalMovieClips; i ++ ) { _root['mc' + i].indexPos = i; _root[ 'mc' + i ].onRelease = function() { trace( 'mc' + this.indexPos + ' onRelease' ); } _root[ 'mc' + i ].onRollOver = function() { trace( 'mc' + this.indexPos + ' onRollOver' ); } _root[ 'mc' + i ].onRollOut = function() { trace( 'mc' + this.indexPos + ' onRollOut' ); } } On 3/30/06, Alejandro Diaz [EMAIL PROTECTED] wrote: 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.i8;_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 ___ Flashcoders@chattyfig.figleaf.com 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 ___ Flashcoders@chattyfig.figleaf.com 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