A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Simplifying this code?

  1. #1
    Senior Member
    Join Date
    Sep 2001
    Location
    Manhattan
    Posts
    398
    This code I am writting seems so redundant and I am sure that there must be a more efficient way to write it. This is only a piece of the code but you should be able to get the point of my question by looking at it.

    slide_1.onPress = pressAction1;
    slide_1.onRelease = releaseAction1;
    slide_1.onReleaseOutside = releaseAction1;
    slide_2.onPress = pressAction2;
    slide_2.onRelease = releaseAction2;
    slide_2.onReleaseOutside = releaseAction2;
    slide_3.onPress = pressAction3;
    slide_3.onRelease = releaseAction3;
    slide_3.onReleaseOutside = releaseAction3;
    slide_4.onPress = pressAction4;
    slide_4.onRelease = releaseAction4;
    slide_4.onReleaseOutside = releaseAction4;
    slide_5.onPress = pressAction5;
    slide_5.onRelease = releaseAction5;
    slide_5.onReleaseOutside = releaseAction5;
    slide_6.onPress = pressAction6;
    slide_6.onRelease = releaseAction6;
    slide_6.onReleaseOutside = releaseAction6;
    slide_7.onPress = pressAction7;
    slide_7.onRelease = releaseAction7;
    slide_7.onReleaseOutside = releaseAction7;

    Thanks a lot

  2. #2
    Developer
    Join Date
    Sep 2001
    Location
    The Bluegrass State Will Flash For Food ™
    Posts
    3,789
    Code:
    for (var a = 1; a < 8; a++) {
         this["slide_" + a].onPress = this["pressAction" + a];
         this["slide_" + a].onRelease = this["releaseAction" + a];
         this["slide_" + a].onReleaseOutside = this["releaseAction" + a];
    }

  3. #3
    No ambitions beyond flash ScimSlave's Avatar
    Join Date
    Sep 2002
    Location
    Germany
    Posts
    131
    hi!
    you can do the following thing, i dont know if it will work with any other version of Flsh but MX (never tried):

    while(i smaller than numberofSliders)
    {
    var curSlider= eval("/slide_"+i);
    //do something with the curSlider...
    i++;
    }

    happy flashing....
    i dont know but i cant use the
    <>
    symbols correctly... sry
    [Edited by ScimSlave on 09-09-2002 at 03:47 PM]

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