----------------------------------------------------------------------------------
6 IMAGE UPLOAD AND PASTE CODE
CRATE BUTTON AND GIVE INSTANCE NAME
BUTTON INSTANCE NAME = random_btn
http://www.rivercitygraphix.com/view-tutorial.php?id=44&sub=Flash&title=Generate-a-Random-Frame-with-AS3
stop();
random_btn.addEventListener(MouseEvent.CLICK, choose);
function choose(event:MouseEvent):void{
var pic_number : Number = 6;
var randomFrame:Number = Math.ceil(Math.random() * pic_number);
trace(randomFrame);
gotoAndStop(randomFrame);
}
------------------------------------------------------------------------------------------
1- CRATE MOVIE CLIP WITH 8 FRAME
2- FIRST CREATE BLANK FRAME
3- ITS UPDATE EVERY TIME YOUR FRAME
http://www.developphp.com/view.php?tid=361
http://codebind.com/category/design-2/flash/
http://jquerytutorial.in/video/adobe+flash/54
stop();
var randNum:Number = Math.floor(Math.random() * 7) + 1;
var fixedFrame:Number = randNum + 1;
gotoAndStop(randNum);
---------------------------------------------------------------------------------------------------------------------
UPPER RANDOM FRAME FUNCTION UNDER TIMER FUNCTION
IT CHANGE AUTOMATICALLY FRAME SLOWLY & RANDOMLY
MAKE 6 SIX FRAMES WITH BITMAP IMAGES AND PASTE BELOW CODE
YOU CAN CHANGE CODE WITH BELOW LINE FOR SLOW TIMER
var myTimer:Timer = new Timer(2000);
---------------------------------------------------------------------------------------------------------------------
stop();
var Count:uint = 0;
Count += 1;
var myTimer:Timer = new Timer(7000);
myTimer.start();
myTimer.addEventListener(TimerEvent.TIMER,CountDown);
function CountDown(event:Event):void{
var randomFrame:Number = Math.ceil(Math.random() * 6 * Count);
trace(randomFrame)
gotoAndStop(randomFrame)
}
---------------------------------------------------------------------------------1- CRATE MOVIE CLIP WITH 8 FRAME
2- FIRST CREATE BLANK FRAME
3- ITS UPDATE EVERY TIME YOUR FRAME
http://www.developphp.com/view.php?tid=361
http://codebind.com/category/design-2/flash/
http://jquerytutorial.in/video/adobe+flash/54
stop();
var randNum:Number = Math.floor(Math.random() * 7) + 1;
var fixedFrame:Number = randNum + 1;
gotoAndStop(randNum);
---------------------------------------------------------------------------------------------------------------------
UPPER RANDOM FRAME FUNCTION UNDER TIMER FUNCTION
IT CHANGE AUTOMATICALLY FRAME SLOWLY & RANDOMLY
MAKE 6 SIX FRAMES WITH BITMAP IMAGES AND PASTE BELOW CODE
YOU CAN CHANGE CODE WITH BELOW LINE FOR SLOW TIMER
var myTimer:Timer = new Timer(2000);
---------------------------------------------------------------------------------------------------------------------
stop();
var Count:uint = 0;
Count += 1;
var myTimer:Timer = new Timer(7000);
myTimer.start();
myTimer.addEventListener(TimerEvent.TIMER,CountDown);
function CountDown(event:Event):void{
var randomFrame:Number = Math.ceil(Math.random() * 6 * Count);
trace(randomFrame)
gotoAndStop(randomFrame)
}
http://www.kongregate.com/forums/4-programming/topics/160927-random-enemy-spawning-as3
http://flash.bigresource.com/ActionScript-3-0-Animated-MovieClip-jumps-around-screen-randomly-nOA2ltK7I.html#SS3jo1ek8
http://premiumcoding.com/flash-as3-tutorial-random-puzzle-effect/
http://www.slideshare.net/MohammedHussein8/multimedia-lecture-actionscript3
http://www.photonstorm.com/topics/game-development/book-reviews
function addEnemy(event:Event){
var newEnemy:Sprite = new Enemy();
newEnemy.x = Math.random()*1000+600;
newEnemy.y = Math.random()*300;
stage.addChild(newEnemy);
stage.addEventListener(Event.ENTER_FRAME, moveEnemy);
function moveEnemy(event:Event){
newEnemy.x -= enemySpeed;
}}
function addEnemy(event:Event){
var newEnemy:Sprite = new Enemy();
newEnemy.x = Math.random()*1000+600;
newEnemy.y = Math.random()*300;
stage.addChild(newEnemy);
stage.addEventListener(Event.ENTER_FRAME, moveEnemy);
}
function moveEnemy(event:Event){
e.target.x -= enemySpeed;
if(e.target.x < 0) {
e.target.removeEventListener(Event.ENTER_FRAME, moveEnemy);
e.target.parent.removeChild(e.target);
}}
class Enemy {
private var speed:int;
public Enemy(speed:int) { this.speed = speed; }
public function Think() : void { x -= speed; }
public function get Dead() : boolean { return x < 0; }}
function EnterFrameHandler(e:Event) : void {
for each(var enemy:Enemy in enemies){ enemy.Think(); }
for(var i:int = enemies.length - 1; i >= 0; i--){
if(enemies[i].Dead()){
if(enemies[i].parent) enemies[i].parent.removeChild(enemies[i]);
enemies.splice(i ,1);
}}}
---------------------------------------------------------------------------------
http://www.developphp.com/view.php?tid=302
Random Number Generator Code
var randNum:Number = Math.floor(Math.random() * 10) + 1;
status_txt.text = ""+randNum;
----------------------------------------------------------------------------------------
http://www.ilike2flash.com/2009/08/generate-random-numbers-in-actionscript.html
/1.
function randomNumbers(min:Number,max:Number) {
var Results:Number=Math.floor(Math.random()*max)+min;
return Results;
}
//2.
generate_btn.addEventListener(MouseEvent.CLICK, showRandomnumber);
//3.
function showRandomnumber(event:MouseEvent):void{
showRandom_txt.text = randomNumbers(1,100);
}
-------------------------------------------------------------------------------------------------------
http://www.brighthub.com/internet/web-development/articles/106130.aspx#imgn_2
How to Make a Dice Roller in Flash
To roll the Dice you need to be able to generate a random number between one and six since that is the range with which the dice is marked. The entire ActionScript source code that controls the dice rolling in this version is this.
function rollDice(event:MouseEvent):void {
var high:Number = 6;
var low:Number = 1;
var rolledNumber:Number = Math.floor(Math.random() * (1 + high - low)) + low;
if(rolledNumber == 1){
gotoAndPlay("one");
}
else if(rolledNumber == 2){
gotoAndPlay("two");
}
else if(rolledNumber == 3){
gotoAndPlay("three");
}
else if(rolledNumber == 4){
gotoAndPlay("four");
}
else if(rolledNumber == 5){
gotoAndPlay("five");
}
else{
gotoAndPlay("six");
}
}
rollButton.addEventListener(MouseEvent.CLICK, rollDice);
------------------------------------------------------------------------------------------------------
Random Generator updated to AS3
http://flanture.blogspot.co.uk/2010/04/random-generator-updated-to-as3.html
// author: FLANTURE http://flanture.blogspot.com
// date: 24 Jan 2009
// updated: 13 Apr 2010 (AS2 -> AS3)
import flash.filters.BlurFilter;
import flash.events.Event;
import flash.text.TextField;
var timerStarted:Boolean = false;
var counter:uint = 0;
var firstDigitStop:uint = 8;
var secondDigitStop:uint = 16;
var thirdDigitStop:uint = 20;
var filter:BlurFilter = new BlurFilter();
var filterArray:Array = new Array();
// function for roll_mc movie clip onPress action. If timer has not started,
// that means there is no action in progress, so we can start one.
roll_mc.addEventListener(MouseEvent.MOUSE_UP, onRoll);
function onRoll(evt:Event):void
{
if (!timerStarted) {
var filter:BlurFilter = new BlurFilter(60, 120, 1);
var filterArray:Array = new Array();
filterArray.push(filter);
num1_txt.filters = filterArray;
var newNumber1:Number = getRan(10);
num1_txt.text = newNumber1;
num2_txt.filters = filterArray;
var newNumber2:Number = getRan(10);
num2_txt.text = newNumber2;
num3_txt.filters = filterArray;
var newNumber3:Number = getRan(10);
num3_txt.text = newNumber3;
timerStarted = true;
}
}
// functions for restoring blur effect
function restoreBlur1() {
num1_txt.filters = new Array(filter);
}
function restoreBlur2() {
num2_txt.filters = new Array(filter);
}
function restoreBlur3() {
filter.blurY = 0;
filter.blurX = 0;
num3_txt.filters = new Array(filter);
}
// next function controls when blur should stop and numbers should display.
addEventListener(Event.ENTER_FRAME, onFrame);
function onFrame(evt:Event):void
{
if (timerStarted) {
if (counter < thirdDigitStop) {
counter += 1;
if (counter == firstDigitStop) {
restoreBlur3();
}
if (counter == secondDigitStop) {
restoreBlur2();
}
} else {
timerStarted = false;
counter = 0;
restoreBlur1();
}
}
}
// you can change firstDigitStop and other variables to suit your needs.
// numbers represent frames, not seconds.
function getRan(max:uint):uint
{
return Math.floor(Math.random()*max);
}
-------------------------------------------------------------------------------------------------------------------
gotoAndPlay random frame array
https://forums.adobe.com/thread/579038?tstart=0
--------------------------------------------------------------------------------------------------------------------// Array for specific random frames
var rdmFrame:Array = new Array();
rdmFrame[0] = "2";
rdmFrame[1] = "3";
rdmFrame[2] = "4";
rdmFrame[3] = "5";
rdmFrame[4] = "6";
rdmFrame[5] = "7";
rdmFrame[6] = "8";
rdmFrame[7] = "9";
rdmFrame[8] = "10";
rdmFrame[9] = "11";
// Random number equation
var randomNumber = Math.floor(Math.random()*10);
// Trace to show randomNumber and Array output
trace(randomNumber,rdmFrame[randomNumber]);
// gotoAndPlay Frame -- I have it set as gotoAndStop right now to see the trace and how its working
gotoAndStop(rdmFrame[randomNumber]);
-----------------------------------------------------------------------------------------------------------------------
RANDOM FUNCTION IN AS2
https://www.youtube.com/watch?v=ZYVzwvMTLgY&feature=youtu.be
1) MAKE 5 BLANK KEY FRAMES ON MAIN TIME LINE
2) LABELIZE FRAME A,B,C, D, E
3) var Num1:Array = new Array("A","B","C","D","E");
PASTE BELOW CODE
OR USE THIS SIMPLE CODE
//IF YOU MAKE 10 FRAMES MOVIE CLIP YOU NEED RANDOM NUMBER 11
this.MOVIE.gotoAndPlay(Math.round(Math.random() * 11));
trace("current frame is:"+MOVIE._currentframe)
Txt1.text = String(MOVIE._currentframe);
OR USE THIS SIMPLE CODE AS2
//AS2 CODE
MOVIE.gotoAndStop(Math.round(Math.random()* 11));
trace("Movie Frame No:"+ MOVIE._currentframe)
Txt1.text = "Movie Frame No:" + " " + String(MOVIE._currentframe);
OR USE THIS SIMPLE CODE AS3
//AS3 CODE
MOVIE.gotoAndStop(Math.round(Math.random() * 11));
trace("Movie Frame No:"+ MOVIE.currentFrame)
Txt1.text = "Movie Frame No:" + " " + String(MOVIE.currentFrame);
----------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------
//http://www.quip.net/blog/2007/flash/how-to-jump-randomly-to-frame-labels-without-repeats
//http://www.quip.net/blog/2006/flash/how-to-jump-random-frame-label
stop();
function RandomFrameLabelAs2(){
var Num1:Array = new Array("A","B","C","D","E");
var Num2:Number = Math.floor(Math.random()* Num1.length);
return Num1[Num2];
}
this.gotoAndStop(RandomFrameLabelAs2());
// RUN RANDOM FUNCTION INSIDE FRAME CODE
btn1.onPress = function (){
gotoAndStop(RandomFrameLabelAs2());
trace(this._currentframe);
}
---------------------------------------------------------------------------------------------------------------------
OR USE WITHOUT FRAME LABELIZE CODE WITH BUTTON
WE HAVE FIVE FRAME SO WE PUT NUMBER 1,2,3,4,5
--------------------------------------------------------------------------------------------------------------------
stop();
function RandomFrameLabelAs2(){
var Num1:Array = new Array(1,2,3,4,5);
var Num2:Number = Math.floor(Math.random()* Num1.length);
return Num1[Num2];
}
this.gotoAndStop(RandomFrameLabelAs2());
// RUN RANDOM FUNCTION INSIDE BUTTON CODE
on(press){
this.gotoAndStop(RandomFrameLabelAs2());
trace(this._currentframe);
}
--------------------------------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=cUzUqloAGdY
https://www.youtube.com/watch?v=rchwTFxid58
======================================================================= https://www.google.co.uk/search?q=RANDOM+NUMBER+AS3+WITHOUT+REPEAT&rlz=1C1GNAM_en-GBGB684GB684&oq=RANDOM+NUMBER+AS3+WITHOUT+REPEAT&aqs=chrome..69i57j0.380j0j7&sourceid=chrome&ie=UTF-8 http://todepoint.com/blog/2011/01/15/random-number-without-repeat/ http://code.strafspul.be/index.php?q=uniquerandom http://www.republicofcode.com/tutorials/flash/as3loops/ https://www.kirupa.com/forum/showthread.php?368195-Random-numbers-from-an-array-without-repeating http://www.kongregate.com/forums/4-programming/topics/63750-equally-weighted-non-repeating-random-integer-as3 =======================================================================
--------------------------------------------------------------------------------------------------------------------
//https://forums.adobe.com/thread/1095476?tstart=0
//http://todepoint.com/blog/2011/01/15/random-number-without-repeat/
import flash.events.Event;
stop();
btn1.addEventListener (MouseEvent.CLICK, random1);
function random1 (evt:Event) {
display1.text = "";
display2.text = "";
display3.text = "";
display4.text = "";
display5.text = "";
display6.text = "";
var r1 = Math.floor(Math.random()*(1+48-1))+1;
var r2 = Math.floor(Math.random()*(1+48-1))+1;
var r3 = Math.floor(Math.random()*(1+48-1))+1;
var r4 = Math.floor(Math.random()*(1+48-1))+1;
var r5 = Math.floor(Math.random()*(1+48-1))+1;
var r6 = Math.floor(Math.random()*(1+48-1))+1;
if (r2 == r1 || r3 == r2 || r4 == r3 || r5 == r4 || r6 == r5) {
return;
}
var liste:Array = new Array();
liste.push(r1,r2,r3,r4,r5,r6);
liste.sort(Array.NUMERIC);
display1.text = String(liste[0]);
display2.text = String(liste[1]);
display3.text = String(liste[2]);
display4.text = String(liste[3]);
display5.text = String(liste[4]);
display6.text = String(liste[5]);
}
----------------------------------------------------------------------------------------------------------------------
Random Frame Button with no Repeat AS2
https://www.kirupa.com/forum/showthread.php?368573-Random-Frame-Button-with-no-Repeat-AS2
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
MAIN TIME LINE LAYER 1 FRAME 1 CODE
HOW IT'S WORK
1) IT SHOW ELEMENT ARRAY IN OUTPUT LIKE : 3,6,4,7,1,2,5
2) WHEN YOU CLICK BUTTON MOVIE GO TO STOP 6
AND SO ON 4,7,1,2,5
FOR ARRAY FIRST ELEMENT TRACE
trace(arrayList02[0])
-------------------------------------------------------------------------------------------------------------------
//Random Frame Button with no Repeat AS2
//https://www.kirupa.com/forum/showthread.php?368573-Random-Frame-Button-with-no-Repeat-AS2
//LAYER 1 FRAME 1 CODE
var i = 0;
function shuffleArray (){
_root.arrayList01 = [1,2,3,4,5,6,7];
_root.arrayList02 = [];
while (_root.arrayList01.length > 0) {
_root.arrayList02.push(_root.arrayList01.splice(Math.round(Math.random() * (_root.arrayList01.length - 1)), 1)[0]);
}
}
shuffleArray();
trace (arrayList02);
var a = arrayList02[i];
mc.gotoAndStop(a);
--------------------------------------------------------------------------------------------------------------------
INSIDE BUTTON CODE
-------------------------------------------------------------------------------------------------------------------
//INSIDE BUTTON BUTTON AS2 CODE
on (release){
_root.i++;
_root.a = _root.arrayList02[_root.i];
_root.mc.gotoAndStop(_root.a);
if (_root.i > _root.arrayList02.length-1){
_root.shuffleArray();
_root.i=0;
_root.a = _root.arrayList02[_root.i];
_root.mc.gotoAndStop(_root.a);
trace (arrayList02)}
}
2 comments
i tried random frame as3 and success. but when i added a question in frame for question page 1 and score in the frame after the last question frame... it give me error: Error #1009: Cannot access a property or method of a null object reference. could you help me dix it or i have to swnd my .fla file? tq
Random Function In As2 As3 - Flash College >>>>> Download Now
>>>>> Download Full
Random Function In As2 As3 - Flash College >>>>> Download LINK
>>>>> Download Now
Random Function In As2 As3 - Flash College >>>>> Download Full
>>>>> Download LINK gK
EmoticonEmoticon