Results 1 to 2 of 2

Thread: Actionscript 2.0 question

  1. #1
    Join Date
    May 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Actionscript 2.0 question

    Hello all...

    I have been playing around with 2.0 actionscript to make some simple learning activities / games. I am wondering how and if you can use a input text box to take several characters and then if they are correct make another movie clip play and goto another frame, etc.

    For example, I am making a quiz and I want a specific movie clip to advance if the user gets the correct answer for calculation that they have put into a input text box.


    Thanks for any help or guidance...

    KB
    Last edited by kelsobrooks; 05-20-2008 at 04:53 PM. Reason: Edit: dynamic text box to Input text box :-)

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

    Default

    Hey KB,

    To target the text within a input text field you have to utilize the textfield.text property. You'll then evaluate that string value against a hardcoded string value or a string type variable.

    So, if you had an input text field with an instance name of "theAnswer", and the correct answer to your question/prompt was "Yellow", you might code something like this:

    Code:
    if(theAnswer.text == "Yellow") {
       movieclip.gotoAndPlay("frame label");
    }
    The highlighted bits are all filler text/variables. You would need to substitute your own, of course. This method works great if you're only evaluating one question/answer. If you have any more, you'll end up with a ton of repetitive code.

    For multiple uses, I suggest that you create a dynamic function that you can call any time you need to do this kind of evaluation. Let's take the same example as above but this time add a submit button with an instance name of "submit". Your code might look like this:

    Code:
    var answer:String = "Yellow";
    submit.onRelease = checkAnswer;
    
    function checkAnswer() {
       if(theAnswer.text == answer) {
          movieclip.gotoAndPlay("frame label");
       }
    }
    Using this, you would only need to change the value of the answer variable, not rewrite the entire function. To reset the variable, you could attach it to the submit button:

    Code:
    submit.onRelease = function() {
        answer = "Yellow";
        checkAnswer();
    }
    or if you're using the timeline (e.g. 1 frame per question), you could declare the variable at the top of each frame.

    In case it's hard to grasp what I'm talking about in the abstract, here are some "real-life" examples. They're not really very usable -- once you submit an answer, you'll have to refresh the page to re-enter a value. There are two types of questions: 1) a text input as you asked about in your question and for good measure 2) a bunch of radio buttons. The ActionScripting differs in both of these examples as the technique to evaluate radio buttons vs. text field strings is different. The Flash 8 and Flash CS3 sources are included on the page and released under Creative Commons NC.

    Hope that helps. If you have any more questions, feel free to post.

  3. The Following User Says Thank You to Medyman For This Useful Post:

    ReadyToLearn (05-21-2008)

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
  •