A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: random code help

  1. #1
    Junior Member
    Join Date
    Aug 2001
    Posts
    21
    hi, i hope that im doing this in the right forum, i am making an educational game for a school assignment and i am in desperate need of coding help, and general flash help.

    im preety new to flash, i have no diffuculty creating good looking images and animation them and stuff but i have little to no idea on how to do the coding which needs to be done. i need a code which would display a random addition equation using numbers between 1-12 and then have the veiwer put in the answer, if correct add 1 to score and play one of 5 right answer animations, if wrong play one of 5 wrong answer animations.

    i hope this makes sense and i would really appreciate help with it!
    thanks for ur time.

  2. #2
    Junior Member
    Join Date
    Jan 2001
    Posts
    17

    Smile

    ok. you'll need 2 dynamic txt fields & 1 input field...

    name the 2 dynamic fields;
    value1
    value2
    name the input txt;
    answer

    place all 3 text fields inside a MC. have the following code on the MC instance (not the MC timeline);

    onClipEvent(load){
    value1 = Math.floor(Math.random(12))+1;
    value2 = Math.floor(Math.random(12))+1;
    }

    make a button to submit the answer inside the MC, with the following code;

    on(release){
    if(answer == value1 + value2){
    _root.score ++;
    //make the answer animation play
    }else{
    //make the wrong answer play
    }
    }

    Basically the clipevent will assign a random number between 1-12 to both dynamic clips whenever the MC is on a new keyframe.
    The button code checks the value of answer is the same value1 & value2. If right adds 1 to a varible on the root timeline called score.
    Depending on how the answer animations are set up in yr movie you shouldn't have too much problem playing a random one. (after all, we cant spoonfeed you everything)

    hope this helps. Happy Flashing!!!

  3. #3

    to general

    Try this, though I will advise you to actually give your problem a try or at least try and break it into small chunks before posting it. asking for a entire thing at once will generally get you no replies.


    This code should go on the first frame of your main timeline:
    Code:
    var a,b;
    var score = 0;
    
    function makeProblem(){
       a = Math.ceil(Math.random()*12);
       b = Math.ceil(Math.random()*12);
    
       problem = a + " + " + b + " = ";
    }
    
    function checkAnswer(){
       //they got it right
       if(answer == (a+b)){
          score++;
          answer = "";
          rightAnimations.gotoAndStop(Math.ceil(Math.random()*5));
          makeProblem();
       //they got it wrong
       }else{
          wrongAnimations.gotoAndStop(Math.ceil(Math.random()*5));
       }
    }
    
    makeProblem();
    this will require you to have a dynamic text field representing the variable "problem" followed by a input text field representing the variable "answer". with a dynamic text field somewhere on the stage representing the variable "score". and finally you need a button on the stage with the following code:

    Code:
    on(release){
       checkAnswer();
    }
    Now this also assumes that you have your wrong and right animations in seperate movieclips. each having five frames and on each frame a movieclip with a different wrong/right animation.

    I hope this can work out for you. If you need any help on the whole dynamic/input text field read the some of the flash help, or something. I am 100% sure you can figure the rest out.

    well looks like someone has already answered but here is mine anyway

    Have fun,

    Miitchell

  4. #4
    Junior Member
    Join Date
    Aug 2001
    Posts
    21

    thanks alot for your help! ill give it a go!

    thanks!

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