• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Frame Random

Explorer ,
Apr 30, 2013 Apr 30, 2013

Copy link to clipboard

Copied

game.png

this is my game layout,

this is basicaly match order of names.

but every time when game reload all the display names are randomly placed.

i think frame random could be work but don't want to repeat the frame

anyone can help me !!!!

TOPICS
ActionScript

Views

2.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 01, 2013 May 01, 2013

assign your names to an array, then randomizes the array:

var namesA:Array=["xxx","yyy",etc];

namesA=shuffle(namesA);

// namesA is now randomized.  you can loop through namesA and present the display names randomly.

// nothing needs to be changed below.

function shuffle(a:Array):Array {

    var len:Number = a.length-1;

    for (var ivar:Number = len; ivar>=0; ivar--) {

        var p:Number = Math.floor(Math.random()*(ivar+1));

        var t = a[ivar];

        a[ivar] = a

;

        a

= t;

    }

    return a;

}

Votes

Translate

Translate
Community Expert ,
Apr 30, 2013 Apr 30, 2013

Copy link to clipboard

Copied

what's the problem and what's the game?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 01, 2013 May 01, 2013

Copy link to clipboard

Copied

first name come then i click 2 if it's order is correct then go to next name

just like quiz

but every time that names are coming in random that's the problem

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 01, 2013 May 01, 2013

Copy link to clipboard

Copied

assign your names to an array, then randomizes the array:

var namesA:Array=["xxx","yyy",etc];

namesA=shuffle(namesA);

// namesA is now randomized.  you can loop through namesA and present the display names randomly.

// nothing needs to be changed below.

function shuffle(a:Array):Array {

    var len:Number = a.length-1;

    for (var ivar:Number = len; ivar>=0; ivar--) {

        var p:Number = Math.floor(Math.random()*(ivar+1));

        var t = a[ivar];

        a[ivar] = a

;

        a

= t;

    }

    return a;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 01, 2013 May 01, 2013

Copy link to clipboard

Copied

so i make all names into movie clip

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 01, 2013 May 01, 2013

Copy link to clipboard

Copied

that doesn't matter for using the code i suggested.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 01, 2013 May 01, 2013

Copy link to clipboard

Copied

var namesA:Array=["a1","a2","a3"];

dynamic textfield name namesA

they are shuffling but output is a1,a2,a3 like this

there is only one name a3 then i click on according button if it's right then display next name...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 01, 2013 May 01, 2013

Copy link to clipboard

Copied

can we jump Randomly to Frame Labels without Repeats

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 01, 2013 May 01, 2013

Copy link to clipboard

Copied

yes, put the frame labels in an array and apply the shuffle function to that array.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 01, 2013 May 01, 2013

Copy link to clipboard

Copied

check this

function shuffle(arr:Array):Void {

  var len:Number = arr.length - 1;

  for (var i:Number = len; i >= 0; i--) {

    var p:Number = Math.floor(Math.random() * (i + 1));

    var t:Object = arr;

    arr = arr

;

    arr

= t;

  }

}

var labels:Array = ["a", "b", "c", "d", "e"];

shuffle(labels);

var currentLabel:Number = 0;

function gotoNextLabel():Void {

  if (currentLabel < labels.length) {

    gotoAndPlay(labels[currentLabel]);

    currentLabel++;

  } else {

    stop();

  }

}

gotoNextLabel();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 01, 2013 May 01, 2013

Copy link to clipboard

Copied

in this random frame label code

when i got it right name then how go to next name

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 01, 2013 May 01, 2013

Copy link to clipboard

Copied

call gotoNextLabel() again.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 01, 2013 May 01, 2013

Copy link to clipboard

Copied

num_plates.num2.onRelease = function ()

{

    if (names.gotoAndStop("b")) // here names is my movie clip inside a to x frame label

    {

        right.gotoAndPlay(2);

        this.gotoAndStop(2);

        updateScore(500);

        this.enabled = false;

        a = a + 1;

        if (a == 24)

        {

            gotoAndStop("over");

        }

   gotoNextLabel();

    }

    else

    {

        updateScore(-100);

        wrong.gotoAndPlay(2);

    }

    

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 01, 2013 May 01, 2013

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 02, 2013 May 02, 2013

Copy link to clipboard

Copied

i didn't find names position

if (names.labels[0] == "a")//

    {

                    right.gotoAndPlay(2);

        this.gotoAndStop(2);

        updateScore(500);

        this.enabled = false;

        a = a + 1;

        if (a == 24)

        {

            gotoAndStop("over");

        }

                    names.gotoNextLabel();

    } //

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 02, 2013 May 02, 2013

Copy link to clipboard

Copied

your code snippets don't make sense.

you'll need to include more code or clearly explain what you're trying to do.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 02, 2013 May 02, 2013

Copy link to clipboard

Copied

it's done!!!

i use this code

if (names.labels[names.currentLabel-1]=="a")

Thank you Kglad once again for your help

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 03, 2013 May 03, 2013

Copy link to clipboard

Copied

you're welcome.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 09, 2013 May 09, 2013

Copy link to clipboard

Copied

Hi Kglad

there is somethng problem n shuffle function

that names shuffle but after some clicks they repeat

Please help

on first frame in name movie clip code is

function shuffle(arr:Array):Void {

  var len:Number = arr.length - 1;

  for (var i:Number = len; i >= 0; i--) {

    var p:Number = Math.floor(Math.random() * (i + 1));

    var t:Object = arr;

    arr = arr

;

    arr

= t;

  }

}

var labels:Array = ["a", "b", "c", "d", "e"];

shuffle(labels);

var currentLabel:Number = 0;

function gotoNextLabel():Void {

  if (currentLabel < labels.length) {

    gotoAndPlay(labels[currentLabel]);

    currentLabel++;

  } else {

    stop();

  }

}

gotoNextLabel();

and main time line button on click code is

if (names.labels[names.currentLabel-1]=="a")

    {

                    right.gotoAndPlay(2);

        this.gotoAndStop(2);

        updateScore(500);

        this.enabled = false;

        a = a + 1;

        if (a == 24)

        {

            gotoAndStop("over");

        }

                    names.gotoNextLabel();

    } //

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 09, 2013 May 09, 2013

Copy link to clipboard

Copied

once you hit the end of the array, you should reapply the shuffle function if you want to re-randomize the array.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 09, 2013 May 09, 2013

Copy link to clipboard

Copied

in "names" movie clip i have 24 frames and in first frame if they all hit

then game is over.

in trace it's shown (b,g,i,a,v,.....) like this there is no repeatation in

array

but here in between frame is repeat.

how i find the solution.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 10, 2013 May 10, 2013

Copy link to clipboard

Copied

once we hit the right match then delete the particuler array

is it possible?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 10, 2013 May 10, 2013

Copy link to clipboard

Copied

you can remove an array element using the splice method. to remove the first array element, use:

labels.splice(0,1);

to remove the last element:

labels.splice(labels.length-1,1);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 14, 2013 May 14, 2013

Copy link to clipboard

Copied

this is working but at one point, array intialized and again shffle the array

i didn't figured out the problem.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 14, 2013 May 14, 2013

Copy link to clipboard

Copied

what problem are you seeing?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines