Flash Advisor logo
:: Desktop Shortcut
:: Flash Help
Advice from Experts

+ Reply to Thread
Results 1 to 4 of 4

Thread: Rolling Dice

  1. #1

    Default Rolling Dice

    Hi guys,

    Got a slight problem so looking for an answer as it has been a very long time since I used AS and now everything has event listeners so I am a bit lost but trying.

    I am in CS5 and wanting to catch up with AS3.

    This code works
    Code:
    /*this.reset.addEventListener(MouseEvent.CLICK,Rand);
    function Rand(event: MouseEvent)
    {
        shapes1.gotoAndStop(1+Math.floor(Math.random()*5));
        shapes2.gotoAndStop(1+Math.floor(Math.random()*5));
        shapes3.gotoAndStop(1+Math.floor(Math.random()*5));
        shapes4.gotoAndStop(1+Math.floor(Math.random()*5));
        shapes5.gotoAndStop(1+Math.floor(Math.random()*5));
        shapes6.gotoAndStop(1+Math.floor(Math.random()*5));
        shapes7.gotoAndStop(1+Math.floor(Math.random()*5));
        shapes8.gotoAndStop(1+Math.floor(Math.random()*5));
        shapes9.gotoAndStop(1+Math.floor(Math.random()*5));
    }*/
    But I am trying to condense it
    Code:
    this.reset.addEventListener(MouseEvent.CLICK,Rand);
    function Rand(event: MouseEvent)
    {
    for (i=1;i<10;i++){
    
     shapes[i].gotoAndStop(1+Math.floor(Math.random()*5));
    }
    Any help would be appreciated.

  2. # ADS
    Join Date
    Always
    Posts
    Many
     
  3. #2
    Join Date
    Jun 2009
    Location
    Houston, Tx
    Posts
    485

    Default

    Hmm.. Idk if the second code you put is copied correctly, but it is missing an end bracket } at the bottom.
    Also, the variable "i" has not been declared in this code. Other than that, it should be fine.

  4. #3

    Default

    Hi Vlykarye,

    Yea I did miss the bracket off in the paste

    but I have done a few changes to this and I am learning a lot of new things within AS3 now.

    My first mistake was to put the movieclips on stage and try and work from there so I made the one instance in the library and calling it to stage.

    Code:
    var numBalls:Number = 5;
    for(var i:Number = 0;i<numBalls;i++)
    Now it is off to learn the setinterval so these are created not all at once.

    any good examples you can point me too?

    Thanks for the reply.

  5. #4
    Join Date
    Jun 2009
    Location
    Houston, Tx
    Posts
    485

    Default

    You use timers. That's the only way.

    There are timers in ActionScript that you can use, or you can make your own by taking advantage of the frame rate and frames.
    Obviously, using the timer objects in the code is better.

Thread Information

Users Browsing this Thread

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

     

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Sponsors
Create Speaking Characters for your website and Flash movies. 15 Day Free Trial