A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: Random remove frames

  1. #1
    Senior Member gordonart's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    267

    Random remove frames

    I have this Random-code where you go to different frames in a mc.

    function MyRandom(minVal, maxVal){
    return minVal + Math.floor(Math.random()*(maxVal +1 - minVal));
    }
    //////
    texter.gotoAndStop(MyRandom(1,8));

    But when the user has been to a frame I want to remove that frame from the "list" so you can´t go there anymore.

    Any good codes for that?

    /Mattias
    Mattias Gordon
    illustrator/ animator

  2. #2
    Senior Member gordonart's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    267
    I found out that had to use Arrays of course.

    var Nummer = new Array(1,2,3,4);
    randomNum = random(Nummer.length);
    //////
    texter.gotoAndStop(randomNum);
    trace("numbers left:" + Nummer);

    I tried to delete the numbers inside the Array with this:

    t1.onRelease = function(){
    delete _parent.Nummer[1];
    _parent._parent.gotoAndPlay(1);
    }

    But it did not work.
    Anyone see what´s wrong?

    /Mattias
    Mattias Gordon
    illustrator/ animator

  3. #3
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    var Nummer = new Array(1, 2, 3, 4);
    
    function randomNum() {
    	return Nummer.splice(random(Nummer.length), 1);
    }
    
    texter.gotoAndStop(randomNum());

  4. #4
    Senior Member gordonart's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    267
    Thanks,
    I got me to remove an Array but I more wanted this:

    I can go to 4 random frames ( it works now).
    On each frame there is a "question".
    If you answer right this frame is "deleted" from the Array and you will not go there any more.
    If you answer wrong you go to another frame but the old frame is still there so you can come back to it.
    So If I answer right on frame 2 I want the number 2 to be deleted so next time you can go to 1,3,4. If you answer then right on frame 4 you will go to random 1 and 3.

    Can you do this with the codes?

    /Mattias
    Mattias Gordon
    illustrator/ animator

  5. #5
    :
    Join Date
    Dec 2002
    Posts
    3,518
    In the quiz, need to set the value of isCorrect, before calling the function.

    Code:
    var Nummer = new Array(2, 3, 4, 5);
    var isCorrect = true;
    var currNum;
    
    function randomNum() {
    	if (Nummer.length == 0) {
    		if (!isCorrect) {
    			return currNum;
    		} else {
    			return 6;
    		}
    	}
    	var newNum = Nummer.splice(random(Nummer.length), 1);
    	if (!isCorrect && currNum != undefined) {
    		Nummer.push(currNum);
    	}
    	currNum = newNum;
    	return newNum;
    }
    If you answer right, number is removed from array. If you answer wrong, go to new page, but puts number back into array. If array empty and answer last question correctly go to page "6".
    Last edited by dawsonk; 09-10-2010 at 11:46 AM.

  6. #6
    Senior Member gordonart's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    267
    Could the codes on on quiz with right answer be like this then:

    t1.onRelease = function(){
    var isCorrect = true;
    _parent._parent.gotoAndPlay(1);
    }
    Mattias Gordon
    illustrator/ animator

  7. #7
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    btnA.onRelease = function() {
    	_parent.isCorrect = true;
    	gotoAndStop(_parent.randomNum());
    };
    btnB.onRelease = function() {
    	_parent.isCorrect = false;
    	gotoAndStop(_parent.randomNum());
    };

  8. #8
    Senior Member gordonart's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    267
    Wonderful, Now it seems to work, or rather now I understand how to do it right.
    You have helped me before dawsonk, thanks again.
    Get back if I get into trouble again.
    /Mattias
    Mattias Gordon
    illustrator/ animator

  9. #9
    Senior Member gordonart's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    267
    Now it seems to work the way I wanted.
    I just have some questions so I learn more. Se comments in the code.


    the code "!isCorrect" means that the isCorrect is false?


    ////this code removes one number from the Array?
    var newNum = Nummer.splice(random(Nummer.length), 1);
    ///// if isCorrect is false the number of the frame is pushed back into the Array?
    if (!isCorrect && currNum != undefined) {
    Nummer.push(currNum);
    }
    currNum = newNum;
    return newNum;
    }

    How does the code know which frame I am so it knows which to remove?
    Mattias Gordon
    illustrator/ animator

  10. #10
    Senior Member gordonart's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    267
    There seems to be a little problem.

    On the first load I always comes to frame 2. That´s ok but when pressing the right choice on frame 2 that frame come back later. That is not the case with the other frames.
    Why could that be?
    Mattias Gordon
    illustrator/ animator

  11. #11
    :
    Join Date
    Dec 2002
    Posts
    3,518
    On the first frame of the random movie, use this code on a button to start the quiz.
    Code:
    beginQuizButton.onRelease = function() {
    	_parent.isCorrect = true;
    	gotoAndStop(_parent.randomNum());
    };
    Sorry I missed this question earlier...

  12. #12
    Senior Member gordonart's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    267
    Thanks!!!!
    Mattias Gordon
    illustrator/ animator

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