5 Replies Latest reply on Jun 12, 2008 6:35 AM by Greenbutton

    Action Script - Open Text File?

    Greenbutton
      I've created a list of text questions on one part of my screen. I'd like the user to be able to click on a particular question and then an answer reveal itself on the other part of the screen. I'd like to keep this all withing the same movie, if possible...I don't want to have to load a different movie for each answer. I'm thinking along the lines of puttin a button over each question and adding some sort of action script to each button that calls up the particular answer. I guess this would also need to take into account that the previous answer gets cleared before a new answer is displayed. Does anyone have some advice on how to accomplish this?
        • 1. Action Script - Open Text File?
          Noelbaland Level 1
          Hello there,

          The simplest way to do this, is to

          1) Create a dynamic textbox on the stage that will hold your answers. Give it an instance name of say "answers". Make sure multiline is selected.

          2) Create a square button and use the transform tool to make it fit and cover your question. Turn the alpha property of your button down to 30 when you do this. Give an instance name of say "question1".

          3) Attach the following script to the button
          on(release){
          _root.answers.text = "Answer to Question 1";
          }

          4) Repeat with other questions by dragging more button instances to the stage and naming them question2, question3, etc.

          If you want to keep all your code in the one place then create a new layer and call it "actions". Then attach the following code for your buttons on the first frame

          question1.onRelease = function(){
          _root.answers.text = "Answer for Question 1";
          }
          question2.onRelease = function(){
          _root.answers.text = "Answer for Question 2";
          }
          etc...

          Before you test or publish your movie, turn your button alpha down to 0 so that it's invisible or you can double cllick on your button and drag/cut the square off the Up frame and put it on the Hit frame. The button becomes see through.

          Hope that helps
          • 2. Re: Action Script - Open Text File?
            Greenbutton Level 1
            Thanks for the helpful suggestion. Using your example I can make this work in a new movie, however, when I try to add this in a movie that I already have made (it's actually a purchased template) it does not work. The button functions as a button, however, when I click on it, no text appears in the dynamic text field. Any idea what might be causing this?
            • 3. Re: Action Script - Open Text File?
              Greenbutton Level 1
              I think I found what could be causing the problem. When I hit "debug" after previewing my movie I see the code below. It appears that a variable is being forced in front of my "answers". I'm sure those variables are being put in front of everything on that template and it seems as though I probably need them to make the rest of my links work. Any ideas?
              • 4. Re: Action Script - Open Text File?
                Noelbaland Level 1
                Hi again,

                Yes it seems the 'answers' textfield is inside a movieclip named 'main'. No problem - just change the script to target the textfield inside the main movieclip.

                question1.onRelease = function(){
                _root.main.answers.text = "Answer for Question 1";
                }

                That should clear that up.

                • 5. Re: Action Script - Open Text File?
                  Greenbutton Level 1
                  I tried your suggestion and it did not work. I see your point though and I believe you're on the right track. If I change the "answers" text field to static text and populate it with some letters and test the movie I can see the text no problem. So I don't believe it's a matter of being in a different movie. I believe there is scripting somewhere that is telling my my buttons that my dynamic text field is located somewhere that it is not. So I figure I either need to alter this overriding script OR actually put the dynamic text field where it thinks it should be. Thoughts now?