Results 1 to 2 of 2

Thread: for Loop?

  1. #1
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default for Loop?

    Hello...

    I am creating a client website.
    I have several thumnails on the wesbite which I'm linking to the larger image through loadMovie();, using code like this:

    Code:
    thumb1.onRelease = function() {
    	unloadMovie(_root.pic);
    	_root.pic.loadMovie("images/1.jpg");
    	_root.black._visible = true;
    	new Tween(_root.black, "_alpha", Regular.easeInOut, 0, 70, 1, true);
    }
    Now, I have 60 thumbnails. Is there a way to do this using a for loop so I don't have to copy and paste the same action for all 60.

    The images and thumb names are the same...i.e. thumb1 links to 1.jpg and thumb60 links to 60.jpg.

    Thanks

  2. #2
    Join Date
    Jan 2007
    Location
    Charlotte, NC
    Posts
    82
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Now I didn't test this but this looks correct to me.

    By making i<= a variable you can just change the totalImages var or, if you want to get crazy with it, set it dynamically.

    the variable thumb = _root: im assuming mc thumb is on the root timeline. This may need to be adjusted.
    Code:
    var totalImages = 60;
    
    for (var i = 0; i<=totalImages; i++) {
         var thumb = _root["thumb"+i];
         thumb.onRelease = function() {
              unloadMovie(_root.pic);
              _root.pic.loadMovie("images/"+i+".jpg");
              _root.black._visible = true;
              new Tween(_root.black, "_alpha", Regular.easeInOut, 0, 70, 1, true);
         }
    }

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •