12 Replies Latest reply on Oct 9, 2006 10:15 PM by bcounts

    Button Code : URGENT

    bcounts Level 1
      I have a code for one of my buttons that tells the button to look to a TXT file for the link. However sometimes I will not have a link for the button and need the button to disable when the word "disabled" is typed where the URL would be in the text field.

      Here is the current code for the button - can someone write some code telling it to disable when it reads the word "disabled" in the TXT file?


      link1.onPress=function(){
      getURL(artlink1,"_blank");


      The TXT variable is called artlink1
        • 1. Re: Button Code : URGENT
          coldMiner Level 1
          something like this?
          • 2. Re: Button Code : URGENT
            bcounts Level 1
            I added it to the code and this is what I came up with - I get an error code saying that this does noot work all the way - can you help debug the code to work. I think you can see what I am trying to do now.


            link1.onPress=function(){
            function enableDisableButton(link1, artlink1){
            if(artlink1=="disabled"){
            link1.enabled = false;
            } else {
            getURL(artlink1,"_blank");
            link1.enabled = true;
            }
            }
            • 3. Button Code : URGENT
              coldMiner Level 1
              hmm... looks like you don't understand... ok:
              look at this code:

              link1.onPress=function(){
              if(artlink1=="disabled"){
              this.enabled = false;
              } else {
              getURL(artlink1,"_blank");
              }
              };

              this makes no sense because you will disable the button WHEN you have pressed it (on press)
              and not BEFORE...
              So in your code you must have a function that checks if artlink1 == "disabled",
              and tells the button link1: link1.enabled = false or link1.enabled = true

              Somewhere in your code you read the artlink1 variable, and that is the place
              to enable or disable the button.
              • 4. Re: Button Code : URGENT
                bcounts Level 1
                Almost there now - I got it to work but I relized that the button does not disable until after it is clicked once. My fault because that what I told it to do.

                What I am trying to do is have it disable when I enter this page of the website if the TXT file reads disabled and if it does not read disabled than for it to load the entered link on button press.

                How would I do this on that button?

                Thank you for all of your help - and thanks for any more in advance!!!!
                • 5. Re: Button Code : URGENT
                  coldMiner Level 1
                  With so little code to work on, I have to suggest something "ugly" :) like this:
                  • 6. Re: Button Code : URGENT
                    bcounts Level 1
                    Now how do I work the two following codes into one another so they will work and not cancel each other out. Also the second code keeps getting an error saying that it has one to many "}" at the end of it.

                    You are a life saver and really helping me out -- THANK YOU SO MUCH!!!!


                    Code 1

                    link1.onEnterFrame = function() {
                    if (artlink1 != undefined) {
                    if (artlink1 == "disabled") {
                    this.enabled = false;
                    } else {
                    this.enabled = true;
                    }
                    delete this.onEnterFrame;
                    }
                    };


                    Code 2

                    link1.onPress=function(){
                    if(artlink1=="disabled"){
                    this.enabled = false;
                    } else {
                    getURL(artlink1,"_blank");
                    }
                    };

                    • 7. Button Code : URGENT
                      ggshow Level 2
                      • 8. Button Code : URGENT
                        bcounts Level 1
                        This just does not seem to be working and my deadline is getting close here. I am trying to have a button call a link from a TXT file.

                        Sometimes there is no link in the TXT file so I type disable at which point I would like the button in the FLA to disabled.

                        I need the button to look on frame enter for the word "disabled" in the TXT file and disable [or] on press load the URL link if one is avaliable in that TXT file.

                        This is the code that I have right now and it is not working.


                        link2.onEnterFrame = function() {
                        if (artlink2 == "disabled") {
                        link2.enabled = false;
                        } else {
                        link2.enabled = true;
                        }
                        link2.onPress=function(){
                        getURL(artlink2,"_blank");
                        }
                        }


                        The button is called link1 and the TXT var is called artlink1.

                        I am loading the TXT file with : loadVariablesNum('Text Files/Home Page.txt,0); I do not think that this has anything to do with the code not working but I thought I would include it just in case.
                        • 9. Button Code : URGENT
                          ggshow Level 2
                          sorry.
                          link2 is the button?
                          there is no onEnterFrame for a button instance!!
                          try this

                          • 10. Re: Button Code : URGENT
                            bcounts Level 1
                            Do I attach the above code to the button or can I put it in with my other actions located in the first frame of my timeline.

                            The reason I ask is because the _root confuses me - if I am attaching to the first frame with all my other action script why do I need to tell it to look in the _root?
                            • 11. Button Code : URGENT
                              ggshow Level 2
                              script attach to frame where your link1 apear, _root not neccessary in your case.

                              you can use:

                              • 12. Re: Button Code : URGENT
                                bcounts Level 1
                                Brilliant!!!!!

                                Thank you so much for everyones help on this issue.

                                Have a wonderful evening and rest of the week :)