The forums have permanently moved to This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 3 of 3

Thread: help in array

  1. #1

    help in array

    Hi,, I want to work check before displaying any information on what it is to not repeated with supply

    My code:
    var sp:Array = new Array( 'Ball' , 'Seq' , 'Circle' , 'Rec');
    btn.addEventListener(MouseEvent.CLICK, Press);
    function Press (event:MouseEvent):void
    txt_1.text = sp[Math.floor(Math.random() * sp.length)];
    txt_2.text = sp[Math.floor(Math.random() * sp.length)];
    txt_3.text = sp[Math.floor(Math.random() * sp.length)];
    txt_4.text = sp[Math.floor(Math.random() * sp.length)];
    txt_5.text = sp[Math.floor(Math.random() * sp.length)];
    txt_6.text = sp[Math.floor(Math.random() * sp.length)];

    I don't want to be in the field for similar txt1 with txt2 and txt3 for example..

  2. #2
    Registered abUser
    can you just store the previous random array index and if the next random one is the same just keep generating a new random one until it is different
    blog (experiments and code)-> <-
    as3 helper/shortcut lib (v1.2) -> <-
    agal helper -> Clicky here <- UPDATED

  3. #3
    Just a logic.. since i do not have a handy code now...
    Create a temp array - copy of your array 'sp'. Now pick random value from this array and remove that element from the array. Once you are finished with temp array, fill it again with original array. This way you will not get repeat elements.

    Hope this helps...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Home About Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012