dcsimg
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [AS3]Random do something without repeat

Hybrid View

  1. #1
    Junior Member
    Join Date
    Jun 2007
    Posts
    20

    [AS3]Random do something without repeat

    Hi,

    I've 3 movieclip on stage which is mc1,mc2,mc3
    at first they are alpha=0

    What I want is when i click on revealBtn, 1 of them will show up as alpha=1.

    But with my code below, sometimes I need to click about 5 times or more only can make all those mc show up.

    Is there any solution for what I wanted?

    var mcArray:Array = [mc1,mc2,mc3];
    for (var j:int = 0; j < mcArray.length; j++)
    {
    mcArray[j].alpha = 0;
    }

    revealBtn.buttonMode = true;
    revealBtn.useHandCursor = false;
    revealBtn.addEventListener(MouseEvent.CLICK, revealClick);

    function revealClick(event:MouseEvent):void
    {
    //Generate random number (integer) between 0 and mcArray.length
    var i:Number = Math.floor(Math.random() * mcArray.length);

    //Select ith element of mcArray
    var movieClipToEdit:MovieClip = mcArray[i] as MovieClip;

    //Change its alpha to 1
    movieClipToEdit.alpha = 1;
    }

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Then it would not be random any more. What you need to do is to select the first button randomly and then deleting the button id from the array. Now the array contains only the two remaining buttons and next time one of those will be selected until only one button is left.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

Tags for this Thread

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center