Thursday, 21 April 2016

RANDOM FRAME NO REPEAT AS2

RANDOM FRAME NO REPEAT AS2

----------------------------------------------------------------------------------------------------------------------
RANDOM FRAME NO REPEAT AS2
0) FRAME RANDOMISE WITH RIGHT ARROW KEY
1) NEED  12 FRAMES ON MAIN TIME LINE LAYER 1
2) NEED 12 DIFFERENT IMAGES FOR EACH FRAME
3)NEED LAYER 2 PAST STOP AND ALL CODE
----------------------------------------------------------------------------------------------------------------------
CODE:
http://board.flashkit.com/board/showthread.php?737266-How-to-go-to-random-scenes-without-repeating-HELP!
http://www.flashandmath.com/howtos/deal/
----------------------------------------------------------------------------------------------------------------------
stop();
var im;
var num;
var frm;
var genum=[];
var k=0;
var myarr=[0,1,2,3,4,5,6,7,8,9];
var noKey = true;
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
if(noKey) {
if(Key.isDown(Key.RIGHT)) {
im=myarr.length;
num=random(im);
frm=myarr[num]+2;
genum.push(frm);
myarr.splice(num,1);
gotoAndStop(frm);
if(im<=1)gotoAndStop(12);
noKey = false;
}}}
keyListener.onKeyUp = function() {
if(!Key.isDown(Key.RIGHT)){
noKey = true;
}
}
Key.addListener(keyListener);
-------------------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------------------------------------------------------------ OR USE BUTTON CODE AS2
OR TRACE ARRAY ELEMENT NUMBER
var genum=[];
trace(genum[0]);trace(genum[1]);trace(genum[2]);trace(genum[3]);trace(genum[4]);
trace(genum[5]);trace(genum[6]);trace(genum[7]);trace(genum[8]);
trace(genum[9]);trace(genum[10]); trace(genum[11]);trace(genum[12]); -------------------------------------------------------------------------------------------------------------------------------------------------------------------
//SIX VARIABLES USE IN THIS CODE stop(); var im; var num; var frm; var genum=[]; var k=0; var myarr=[0,1,2,3,4,5,6,7,8,9]; Bn1.onPress= function(){ im=myarr.length; num=random(im); frm=myarr[num]+2; genum.push(frm); myarr.splice(num,1); gotoAndStop(frm); if(im<=1)gotoAndStop(12); }
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
OR USE TRACE FRAME NUMBER
trace(frm);Txt1.text =(frm);
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
RANDOM FRAME NO REPEAT AS2
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
OR USE THIS CODE AS2
OR USE THIS CODE FOR AS3
JUST CHANGE BUTTON FUNTION
Bn1.addEventListener(MouseEvent.CLICK,Fn1);
function Fn1(event:MouseEvent):void{
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
stop();
var EmptyArray=[];
var FillArray =[0,1,2,3,4,5,6,7,8,9];
Bn1.onPress = function(){
var Num1  = FillArray.length;
var Num2  = Math.floor(Math.random() * Num1);
var FrameNo = FillArray[Num2]+2;
EmptyArray.push(FrameNo);
FillArray.splice(Num2,1);
gotoAndStop(FrameNo);
trace(FrameNo);
Txt1.text =(FrameNo);
if(Num1<=1)gotoAndStop(12);
}
-------------------------------------------------------------------------------------------------------------------------
OR USE CODE WITH TWO  12 FRAME BUTTONS
IT SHOWS 10 DIGITS NOT SHOW 0,1,12
10,4,5,2,6,9,7,11,8,3

-------------------------------------------------------------------------------------------------------------------------
stop();
Bn1.onPress = function (){
RandomNumberAs2();
}
Bn2.onPress = function (){
RandomNumberAs2();
}
var EmptyArray=[];
var FillArray =[0,1,2,3,4,5,6,7,8,9];
function RandomNumberAs2(){
var Num1  = FillArray.length;
var Num2  = random(Num1);
var FrameNo = FillArray[Num2]+2;
EmptyArray.push(FrameNo);
FillArray.splice(Num2,1);
gotoAndStop(FrameNo);
trace(FrameNo);
Txt1.text =(FrameNo);
if(Num1<=1)gotoAndStop(12)
}

RandomNumberAs2();
-------------------------------------------------------------------------------------------------------------------------
RANDOM COUNTER NO REPEAT AS2 AS3
OR USE THIS CODE AS2
OR USE THIS CODE FOR AS3
JUST CHANGE BUTTON FUNTION
Bn1.addEventListener(MouseEvent.CLICK,Fn1);
function Fn1(event:MouseEvent):void{
-------------------------------------------------------------------------------------------------------------------------
stop();
var EmptyArray=[];
var FillArray =[0,1,2,3,4,5,6,7,8,9];
Bn1.onPress = function(){
var Num1  = FillArray.length;
var Num2  = Math.floor(Math.random() * Num1);
var FrameNo = FillArray[Num2]+2;
EmptyArray.push(FrameNo);
FillArray.splice(Num2,1);
trace(FrameNo);
Txt1.text =(FrameNo);
Txt2.appendText([FrameNo]+", ")
}
-------------------------------------------------------------------------------------------------------------------------
RANDOM COUNTER NO REPEAT AS2 AS3 SHOT CODE
OR USE THIS CODE AS2
OR USE THIS CODE FOR AS3
JUST CHANGE BUTTON FUNTION
Bn1.addEventListener(MouseEvent.CLICK,Fn1);
function Fn1(event:MouseEvent):void{
IT SHOWS 10 DIGITS
IT SHOWS 1 TO 10 DIGITS RANDOMLY
NEED CHANGE THIS LINE: var FillArray =[1,2,3,4,5,6,7,8,9,10];
5,2,10,8,7,9,1,6,3,4
NEED CHANGE THIS LINE  var FrameNo = FillArray[Num2]+2;
var FrameNo = FillArray[Num2];
READ MORE:
http://flashcollege.blogspot.co.uk/2016/04/random-counter-no-repeat-with-splice.html
-------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------
var FillArray =[1,2,3,4,5,6,7,8,9,10];
function RandomNumberAs2(){
var Num1  = FillArray.length;
var Num2  = random(Num1);
var FrameNo = FillArray[Num2];
FillArray.splice(Num2,1);
trace(FrameNo);
Txt1.text =(FrameNo);
}
RandomNumberAs2();

Bn1.onPress = function (){
RandomNumberAs2();
}
Bn2.onPress = function (){
RandomNumberAs2();
}
Bn3.onPress = function (){
RandomNumberAs2();
}
Bn4.onPress = function (){
RandomNumberAs2();
}
Bn5.onPress = function (){
RandomNumberAs2();
}
Bn6.onPress = function (){
RandomNumberAs2();
}
Bn7.onPress = function (){
RandomNumberAs2();
}
Bn8.onPress = function (){
RandomNumberAs2();
}
Bn9.onPress = function (){
RandomNumberAs2();
}
-------------------------------------------------------------------------------------------------------------------------
OR USE THIS CODE IN AS2 
IT SHOWS 10 DIGITS
IT SHOWS 0 TO 9 DIGITS RANDOMLY
5,9,7,4,0,8,2,1,3,6
NEED CHANGE THIS LINE  var FrameNo = FillArray[Num2]+2;
var FrameNo = FillArray[Num2];
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
Bn1.onPress = function (){
RandomNumberAs2();
}
var EmptyArray=[];
var FillArray =[0,1,2,3,4,5,6,7,8,9];
function RandomNumberAs2(){
var Num1  = FillArray.length;
var Num2  = random(Num1);
var FrameNo = FillArray[Num2];
EmptyArray.push(FrameNo);
FillArray.splice(Num2,1);
gotoAndStop(FrameNo);
trace(FrameNo);
Txt1.text =(FrameNo);
if(Num1<=1)gotoAndStop(12)
}
RandomNumberAs2();
------------------------------------------------------------------------------------------------------------------------
OR USE THIS CODE IN AS2 
IT SHOWS 10 DIGITS
IT SHOWS 1 TO 10 DIGITS RANDOMLY
NEED CHANGE THIS LINE: var FillArray =[1,2,3,4,5,6,7,8,9,10];
5,2,10,8,7,9,1,6,3,4
------------------------------------------------------------------------------------------------------------------------
 USE THIS CODE IN AS2
------------------------------------------------------------------------------------------------------------------------
Bn1.onPress = function (){
RandomNumberAs2();
}
Bn2.onPress = function (){
RandomNumberAs2();
}
Bn3.onPress = function (){
RandomNumberAs2();
}
Bn4.onPress = function (){
RandomNumberAs2();
}
Bn5.onPress = function (){
RandomNumberAs2();
}
Bn6.onPress = function (){
RandomNumberAs2();
}
Bn7.onPress = function (){
RandomNumberAs2();
}
Bn8.onPress = function (){
RandomNumberAs2();
}
Bn9.onPress = function (){
RandomNumberAs2();
}
var EmptyArray=[];
var FillArray =[1,2,3,4,5,6,7,8,9,10];
function RandomNumberAs2(){
var Num1  = FillArray.length;
var Num2  = random(Num1);
var FrameNo = FillArray[Num2];
EmptyArray.push(FrameNo);
FillArray.splice(Num2,1);
gotoAndStop(FrameNo);
trace(FrameNo);
Txt1.text =(FrameNo);
if(Num1<=1)gotoAndStop(12)
}

RandomNumberAs2();






1 comments:

HOLA AMIGO QUE TAL...AYUDAME CON ALGO POR FAVOR QUIERO HACER UN TEST DE 20 PREGUNTAS...EL TOTAL DE PREGUNTAS ES DE 250 PERO SOLO QUIERO Q ME MUESTRE 20 AL AZAR..ME AYUDAS COMO PUEDO HACER..ESTOY USANDO AS2


EmoticonEmoticon