1 Reply Latest reply on Jan 27, 2007 8:29 AM by Newsgroup_User

    Need Help Bad with UI Components value

    Level 7

      I have a forward button and I have a back button and 4 checkboxes
      Component

      what I trying to make is a game.

      well the game has 5 frame all with back and forward buttons and 4
      checkboxes and some radiobutton on them.

      My Problem is that when I go back the checkbox or radiobutton value
      will not retain their value.


      I'm new to AS2 and I'm trying to as I go.

      Right now I have the actionscript for flash book by kristian besley and
      sham bhangal. great book, but its not helping me on what i need to do.


      I know I need to store the values as _global variables. I'm not sure
      how to do this.

      here is the code i have tried.


      stop();


      var arrCorrectAnswer:Array = new Array(1, 2, 3, 4);
      var arrUserAnswer:Array;
      var arrUserAnswerCopy:Array;
      var nCurrentQuestion:Number = 1;
      //var nTotalQuestion:Number=4;
      var nTotalScore:Number = 0;
      var btn_pressed:String;
      var i:Number = 0;
      function init() {
      arrUserAnswer = new Array();
      for (var i = 0; i<arrCorrectAnswer.length; i++) {
      arrUserAnswer = null;
      }

      }
      init();
      //next button logic - final score display if we finish all questions (4
      in my case)
      next_btn.onRelease = function() {
      btn_pressed = "nxt";
      nextFrame();
      chk_ans();
      if (nCurrentQuestion>=4) {
      displayFinalAnswer();
      }
      };

      //function used to check the correct answer
      function chk_ans() {
      if (radioGroup.selection == _level0.r1) {
      arrUserAnswer[nCurrentQuestion-1] = 1;
      } else if (radioGroup.selection == _level0.r2) {
      arrUserAnswer[nCurrentQuestion-1] = 2;
      } else if (radioGroup.selection == _level0.r3) {
      arrUserAnswer[nCurrentQuestion-1] = 3;
      } else if (radioGroup.selection == _level0.r4) {
      arrUserAnswer[nCurrentQuestion-1] = 4;
      } else {
      arrUserAnswer[nCurrentQuestion-1] = null;
      }
      }
      function displayUserAns() {
      if (btn_pressed == "prev") {
      if (arrUserAnswer[nCurrentQuestion-1] == 1) {
      r1.selected = true;
      } else if (arrUserAnswer[nCurrentQuestion-1] == 2) {
      r2.selected = true;
      } else if (arrUserAnswer[nCurrentQuestion-1] == 3) {
      r3.selected = true;
      } else if (arrUserAnswer[nCurrentQuestion-1] == 4) {
      r4.selected = true;
      }
      } else if (btn_pressed == "prev") {
      if (arrUserAnswer[nCurrentQuestion] == 1) {
      r1.selected = true;
      } else if (arrUserAnswer[nCurrentQuestion] == 2) {
      r2.selected = true;
      } else if (arrUserAnswer[nCurrentQuestion] == 3) {
      r3.selected = true;
      } else if (arrUserAnswer[nCurrentQuestion] == 4) {
      r4.selected = true;
      }
      }
      }
      //function that is used to do the marking (for every right answer,
      score will added to 3 //units and for every wrong answer, reduced to
      -1
      function displayFinalAnswer() {
      for (i=0; i<arrCorrectAnswer.length; i++) {
      if (arrUserAnswer
      == arrCorrectAnswer ) {
      nTotalScore = nTotalScore+1;
      trace("The Question"+arrUserAnswer
      +"Score is"+" :"+nTotalScore);
      } else if (arrUserAnswer == null) {
      //trace("The Question"+arrUserAnswer
      +"Score is"+"
      :"+nTotalScore);
      } else if (arrUserAnswer != arrCorrectAnswer &&
      arrUserAnswer != null) {
      nTotalScore = nTotalScore+1;
      trace("The Question"+arrUserAnswer
      +"Score is"+" :"+nTotalScore);
      //trace(nTotalScore);
      }
      //trace(nTotalScore);
      }
      trace(nTotalScore);
      _root.score = nTotalScore;
      _root.gotoAndStop("score");
      }
      // I have completed the test button
      score_btn.onRelease = function() {
      displayUserAnswer();
      displayFinalAnswer();
      };





      and this on the next frame


      stop();

      back_btn.onRelease = function() {
      btn_pressed = "prev";
      prevFrame();
      chk_ans();
      nCurrentQuestion = nCurrentQuestion -1;
      displayUserAns();
      }

      score_btn.onRelease = function() {
      displayUserAnswer();
      displayFinalAnswer();
      };

      function displayUserAns() {
      if (btn_pressed == "prev") {
      r1.selected = true;
      } else if (load){
      r2.selected = true;
      } else if (load){
      r3.selected = true;
      } else if (load){
      r4.selected = true;
      }
      }


        • 1. Re: Need Help Bad with UI Components value
          Level 7

          Motor Wrote:
          > I have a forward button and I have a back button and 4 checkboxes
          > Component
          >
          > what I trying to make is a game.
          >
          > well the game has 5 frame all with back and forward buttons and 4
          > checkboxes and some radiobutton on them.
          >
          > My Problem is that when I go back the checkbox or radiobutton value
          > will not retain their value.
          >
          >
          > I'm new to AS2 and I'm trying to as I go.
          >
          > Right now I have the actionscript for flash book by kristian besley and
          > sham bhangal. great book, but its not helping me on what i need to do.
          >
          >
          > I know I need to store the values as _global variables. I'm not sure
          > how to do this.
          >
          > here is the code i have tried.
          >
          >
          > stop();
          >
          >
          > var arrCorrectAnswer:Array = new Array(1, 2, 3, 4);
          > var arrUserAnswer:Array;
          > var arrUserAnswerCopy:Array;
          > var nCurrentQuestion:Number = 1;
          > //var nTotalQuestion:Number=4;
          > var nTotalScore:Number = 0;
          > var btn_pressed:String;
          > var i:Number = 0;
          > function init() {
          > arrUserAnswer = new Array();
          > for (var i = 0; i<arrCorrectAnswer.length; i++) {
          > arrUserAnswer = null;
          > }
          >
          > }
          > init();
          > //next button logic - final score display if we finish all questions (4
          > in my case)
          > next_btn.onRelease = function() {
          > btn_pressed = "nxt";
          > nextFrame();
          > chk_ans();
          > if (nCurrentQuestion>=4) {
          > displayFinalAnswer();
          > }
          > };
          >
          > //function used to check the correct answer
          > function chk_ans() {
          > if (radioGroup.selection == _level0.r1) {
          > arrUserAnswer[nCurrentQuestion-1] = 1;
          > } else if (radioGroup.selection == _level0.r2) {
          > arrUserAnswer[nCurrentQuestion-1] = 2;
          > } else if (radioGroup.selection == _level0.r3) {
          > arrUserAnswer[nCurrentQuestion-1] = 3;
          > } else if (radioGroup.selection == _level0.r4) {
          > arrUserAnswer[nCurrentQuestion-1] = 4;
          > } else {
          > arrUserAnswer[nCurrentQuestion-1] = null;
          > }
          > }
          > function displayUserAns() {
          > if (btn_pressed == "prev") {
          > if (arrUserAnswer[nCurrentQuestion-1] == 1) {
          > r1.selected = true;
          > } else if (arrUserAnswer[nCurrentQuestion-1] == 2) {
          > r2.selected = true;
          > } else if (arrUserAnswer[nCurrentQuestion-1] == 3) {
          > r3.selected = true;
          > } else if (arrUserAnswer[nCurrentQuestion-1] == 4) {
          > r4.selected = true;
          > }
          > } else if (btn_pressed == "prev") {
          > if (arrUserAnswer[nCurrentQuestion] == 1) {
          > r1.selected = true;
          > } else if (arrUserAnswer[nCurrentQuestion] == 2) {
          > r2.selected = true;
          > } else if (arrUserAnswer[nCurrentQuestion] == 3) {
          > r3.selected = true;
          > } else if (arrUserAnswer[nCurrentQuestion] == 4) {
          > r4.selected = true;
          > }
          > }
          > }
          > //function that is used to do the marking (for every right answer,
          > score will added to 3 //units and for every wrong answer, reduced to
          > -1
          > function displayFinalAnswer() {
          > for (i=0; i<arrCorrectAnswer.length; i++) {
          > if (arrUserAnswer
          == arrCorrectAnswer ) {
          > nTotalScore = nTotalScore+1;
          > trace("The Question"+arrUserAnswer
          +"Score is"+" :"+nTotalScore);
          > } else if (arrUserAnswer == null) {
          > //trace("The Question"+arrUserAnswer
          +"Score is"+"
          > :"+nTotalScore);
          > } else if (arrUserAnswer != arrCorrectAnswer &&
          > arrUserAnswer != null) {
          > nTotalScore = nTotalScore+1;
          > trace("The Question"+arrUserAnswer
          +"Score is"+" :"+nTotalScore);
          > //trace(nTotalScore);
          > }
          > //trace(nTotalScore);
          > }
          > trace(nTotalScore);
          > _root.score = nTotalScore;
          > _root.gotoAndStop("score");
          > }
          > // I have completed the test button
          > score_btn.onRelease = function() {
          > displayUserAnswer();
          > displayFinalAnswer();
          > };
          >
          >
          >
          >
          >
          > and this on the next frame
          >
          >
          > stop();
          >
          > back_btn.onRelease = function() {
          > btn_pressed = "prev";
          > prevFrame();
          > chk_ans();
          > nCurrentQuestion = nCurrentQuestion -1;
          > displayUserAns();
          > }
          >
          > score_btn.onRelease = function() {
          > displayUserAnswer();
          > displayFinalAnswer();
          > };
          >
          > function displayUserAns() {
          > if (btn_pressed == "prev") {
          > r1.selected = true;
          > } else if (load){
          > r2.selected = true;
          > } else if (load){
          > r3.selected = true;
          > } else if (load){
          > r4.selected = true;
          > }
          > }


          ok i even when so much as just making small clip



          stop();

          back_button.onRelease = function(){
          prevFrame();


          }

          function cchload():Void{
          var cch1:Boolean = (cch.selected = true);
          trace(cch);
          }


          stop();


          cch.label = "opt in";
          cch.selected = false

          var oListener:Object = new Object();
          oListener.click = function(oEvent:Object):Void{
          trace(cch)

          }

          cch.addEventListener("click", oListener);


          function cchload():Void{
          var cch1:Boolean = (cch.selected = true);
          trace(cch);
          }



          really what i'm i doing wrong?

          It seem like this should be the easy, but i'm just lost for words now.