Skip to main content
dof0x
Participant
July 8, 2014
Question

How can I create a button with a random event?

  • July 8, 2014
  • 1 reply
  • 130 views

Well for example I have a deck of 52 cards, and I want the cards to be in different order everytime the game starts.

thanks

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
July 8, 2014

use the shuffle function to reorder arrays,

function shuffle(a:Array) {

    var p:int;

    var t:*;

    var ivar:int;

    for (ivar = a.length-1; ivar>=0; ivar--) {

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

        t = a[ivar];

        a[ivar] = a

;

        a

= t;

    }

}