A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Button play random layer animation?

  1. #1
    Senior Member
    Join Date
    Aug 2007
    Posts
    228

    Button play random layer animation?

    Firs thing version Flash 8
    I hope this is the right place to post it, random functions are under math so I assume it is.
    I have no idea how to do this, I have some basic knowledge of C++ but it does not help me here.
    I want a button to do a random number, and based on that number it will set a variable, and play animations on specified layers.

    if you cant help, maybe someone could just give me a resource, on doing random numbers, and setting variables?

  2. #2
    Senior Member ozmic66's Avatar
    Join Date
    Oct 2005
    Posts
    472
    Here's how you make a variable of type Number (equivalent to C's double)

    Code:
    var x:Number;
    you can then set it like so:

    Code:
    x = 10;
    To get a random number, use the Math.random() function. This returns a floating point # between 0 and 1.

    You can then scale that number to have a wider range. For example, here's how you'd get a random (whole) number between 0 - 10

    Code:
    var x:Number = Math.round(Math.random()*10)
    I'm not sure what you mean by playing an animation in a certain layer. In flash you can't really tell what layers objects are in by code. You can control them by the name of the movieclips though
    Pixelwave Flash-based iPhone framework
    iPhone Games: Flyloop | Freedom Run

    Twitter: Oztune

  3. #3
    Senior Member
    Join Date
    Aug 2007
    Posts
    228

    RE: random numbers

    Now im curious, how do random numbers in Flash/action script work? C++ random numbers arent truly random, but you can modify a script to multiply random number, and get a variable from checking the actual time, that way every second you would get a new number, otherwise if you simply did random number if you restarted a program you would notice the same pattern every time, not truly random.
    does the random script in flash/acitonscript need to be modified that way as well?

  4. #4
    Senior Member ozmic66's Avatar
    Join Date
    Oct 2005
    Posts
    472
    From what I understand, Flash works very similarly, but is a bit more 'automated'.

    In lower level languages I guess you'd need to 'seed' the generator with some value which will dictate the pattern (after all it's a function where different inputs will give you different outputs). Flash seeds the generator automatically every time the application starts.. and my best guess would be that it just uses the current time

    For more info I'd refer you here
    http://lab.polygonal.de/2007/04/21/a...enerator-prng/
    Last edited by ozmic66; 09-07-2007 at 03:18 PM.
    Pixelwave Flash-based iPhone framework
    iPhone Games: Flyloop | Freedom Run

    Twitter: Oztune

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