Ultrashock Forums > Flash > ActionScript
Loops, Eval, and variables. Help.

You are currently viewing our website as a guest which gives you limited access to forums, files and other resources.

Click here to join now for free, and start interacting with our members, download files and much more!

Click here if you are looking for our Flash files and other professional assets.
 
Post Reply | View first unread | Rate Thread Search this Thread | Thread Tools | Display Modes

#1
Bookmark and Share!
Loops, Eval, and variables. Help.
Old 2006-05-29

I am trying to take this code and make it into a loop.

ActionScript Code:
  1. b1.onRelease = function(){
  2.     specificItem(0);
  3. }
  4. b2.onRelease = function(){
  5.     specificItem(1);   
  6. }
  7. b3.onRelease = function(){
  8.     specificItem(2);
  9. }
  10. b4.onRelease = function(){
  11.     specificItem(3);
  12. }
  13. b5.onRelease = function(){
  14.     specificItem(4);
  15. }
  16. b6.onRelease = function(){
  17.     specificItem(5);
  18. }
  19. b7.onRelease = function(){
  20.     specificItem(6);
  21. }
  22. b8.onRelease = function(){
  23.     specificItem(7);
  24. }
  25. b9.onRelease = function(){
  26.     specificItem(8);
  27. }
  28. b10.onRelease = function(){
  29.     specificItem(9);
  30. }

Can someone tell me why this isnt working?

ActionScript Code:
  1. for(i=1;i>=10;i++){
  2.     eval("b"+i).onRelease = function(){
  3.         eval("specificItem("+i-1+")");
  4.     }
  5. }


Thanks.
Version 2 En Route - http://www.johnsonmedia.net
postbit arrow 2 comments | 121 views postbit arrow Reply: with Quote   
Registered User
phlop is offline
seperator
Posts: 129
2005-07-16
seperator

Ultrashock Member Comments:
Nutrox's Avatar Nutrox Nutrox is offline Super Moderator Nutrox lives in United Kingdom 17 Creative Assets 2006-05-29 #2 Old  
Have a play with this.

ActionScript Code:
  1. var i = 1;
  2. var n = 10;
  3.  
  4. while( i <= n ) {
  5.    this["b" + i].id = i - 1;
  6.    this["b" + i].onRelease = myFunc;
  7.    i ++;
  8. }
  9.  
  10. function myFunc()
  11. {
  12.    trace( this + " was clicked" );
  13.    trace( "id = " + this.id );
  14. }
Reply With Quote  
phlop phlop is offline 2006-05-30 #3 Old  
Thanks a ton Nutrox, I knew I was forgetting how AS works! hah
Reply With Quote  
Thread Tools
Display Modes Rate This Thread
Rate This Thread: