Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 9 of 9

Thread: Redundant code help

  1. #1

    Redundant code help

    Can someone consolidate this code:

    Maybe as a funtion or something.

    I know there has to be a better way of doing this. Im not very good at AS.
    Ill offer you 10-15 bucks for the first person who can give me a working answer. Thanks for your time! I have lot of other stuff I need help with too.

    Thanks!

    // TEACHING QUESTIONS
    if (_root.TQ1Completed == "6") {
    TQcheckMark1._visible = true;
    } else {
    TQcheckMark1._visible = false;
    }
    if (_root.TQ2Completed == "5") {
    TQcheckMark2._visible = true;
    } else {
    TQcheckMark2._visible = false;
    }
    if (_root.TQ3Completed == "4") {
    TQcheckMark3._visible = true;
    } else {
    TQcheckMark3._visible = false;
    }
    if (_root.TQ4Completed == "3") {
    TQcheckMark4._visible = true;
    } else {
    TQcheckMark4._visible = false;
    }
    if (_root.TQ5Completed == "4") {
    TQcheckMark5._visible = true;
    } else {
    TQcheckMark5._visible = false;
    }

    The "numbers" correspond to the number of sections in the question.
    For example "TQ1Completed" has "6" sections and so on.

  2. #2
    Hello, I don't really get what you want in the if statement (ex: == "4") How is "4" determined?


    tqstart = 1;
    tqend = 5;
    for (i=tqstart; i<=tqend; i++){
    if (_root["TQ" + i + "Completed"] == idontgetwhatyouwanthere){
    _root["TQcheckMark" + i]._visible = true;
    }else{
    _root["TQcheckMark" + i]._visible = false;
    }
    }


    EDIT:
    Wait, I think this is what you want:

    sections = array(6,5,4,3,4);

    for (i=0; i<sections.length; i++){
    if (_root["TQ" + (i+1) + "Completed"] == sections[i]){
    _root["TQcheckMark" + (i+1)]._visible = true;
    }else{
    _root["TQcheckMark" + (i+1)]._visible = false;
    }
    }


    -freeskier89
    Last edited by freeskier89; November 19th, 2005 at 01:59 AM.

  3. #3
    freeskier89 thanks for the quick reply.

    I type this number (ex: == "4") in by hand.

    The (ex: == "4") corresponds to the amount of sections in the teaching question.

    So (ex: == "4") has 4 sections in the teahing question.

    Thanks!

    -T

  4. #4
    Did you check my edited post?
    Is that what you want?

  5. #5
    Oh crap that was fast.
    That looks about right. Im gonna try it.

    PM me your pay pal address please.

    -T

  6. #6
    Ok I just realized you might need a "new" in front "array"


    sections = new Array(6,5,4,3,4);

    for (i=0; i<sections.length; i++){
    if (_root["TQ" + (i+1) + "Completed"] == sections[i]){
    _root["TQcheckMark" + (i+1)]._visible = true;
    }else{
    _root["TQcheckMark" + (i+1)]._visible = false;
    }
    }


    Hope it works

  7. #7
    Did i do this right?

    I needed to target the same timeline the script was in so I used "this" on the _visible commands and it worked. Is that ok? or should I use something else?

    // TEACHING QUESTIONS SCRATCH OFF
    sections = new array(6, 5, 4, 3, 4);
    for (i=0; i<sections.length; i++) {
    if (_root["TQ"+(i+1)+"Completed"] == sections[i]) {
    this["TQcheckMark"+(i+1)]._visible = true;
    } else {
    this["TQcheckMark"+(i+1)]._visible = false;
    }
    }

    Thanks!
    -T

  8. #8
    You've got it . "this" will work fine, and is probably the best thing to use if it is on the same timeline.

  9. #9
    im gonna just show off, lol

    this["TQcheckMark"+(i+1)]._visible = (_root["TQ"+(i+1)+"Completed"] == sections[i]);

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012