Trigger random part of an animation

Hi everyone,
I have an animation with 5 different parts. I would like to trigger a random part when clicking on a button.
In order to do that I put labels on all parts (play1,...,play5). Then I put a code on the button on the click event :
var RandomNb=Math.floor(Math.random()*5)
if(RandomNb=1){sym.play("play1");}
It is just a simple test but it does not work : the animation play1 is always played no matter the value of RandomNb.
I obviously make something wrong but I don't know what...
Thanks in advance for your help !

Hi, grouchou-
There are a couple of issues with your code.  First off, Math.random() will give you a number between 0 and 1.  I'd suggest you multiply by 100, apply Math.floor(), then modulo 5 to get a random number between 0 and 4.  Secondly, you will need to use the comparison == instead of the assignment = in order to get your if statement to work.  So (if RandomNb == 1) {...}.  Right now, you're doing an assignment in the if statement, which always returns true after it finishes.
Hope that helps,
-Elaine

Similar Messages

  • Divide a number into random parts

    I need to divide a number into a collection of random parts. So that the sum of all parts is equal to the number.
    E.g.:
    public void divideRandomly ( int number, int parts)
    int[] returnArray = new int[parts];
    //do random division calculations
    return returnArray;
    Lets say the number = 20
    And parts = 4
    I would then like to return an array of ints containing e.g. 3, 11, 5, 1
    OR e.g. 4,8,2,6
    Does anyone have a clue as to how I could do this?
    Cheers

    Be aware that given the wrong parameters this solution
    can take a long time to find a list. This seems misleading, as the termination condition is based
    on randomness. Although, it is possible to predict an average
    termination time.
    Basically your algorithm starts by generating initial random values
    in the range [0, maxValue]. You limit the size of the maximum
    generated value, although I'm not sure why. Obviously maxValue
    has to be greater than sum / length, otherwise it would be
    impossible to generate any combination values that add up to sum.
    Then your algorithm asks if the sum of those initial random values
    is equal to the target sum. If not, you cycle through the list replacing
    the the current position with a new random value and updating the
    current sum.
    As an example, let's suppose that maxValue is equal to sum, and
    that sum = 1000, and length (numParts) is 4.
    Assuming the minValue is 1, not 0, then the total number of
    permutations of 4 numbers that add up to 1000 is:
    165,668,499
    However, the total number of permutations is:
    1000^4 = 1,000,000,000,000
    In terms of probability, the chance of finding a solution on each try is:
    165,668,499 / 1,000,000,000,000 = 0.000165668499
    Thus, you'll need approximately 6036 loops on average to find a solution for 1,000 split 4 ways.
    For 2,000 split 4 ways, number of perms is:
    2000^4 = 16,000,000,000,000
    The perms of 4 numbers that add up to 2000 is:
    1,329,336,999
    Probability of finding a solution on each try is:
    0.0000830835624375
    Average number of tries is: 12036
    I'm impressed that the random approach is that fast.

  • Tinting part of an animated movie clip

    Hello - I have a need to tint part of an animated movie clip. For example, I might have a movie clip that consists of 2 layers, 1 layer that is tinted, and one layer that is not tinted. The animation needs to be done by an artist - it is not an algorithmic animation.
    One way to do this is to make each layer a separate movie clip. Then I can apply a tint using the colorTransform property in ActionScript 3 on the 2nd movie clip. This works correctly but has several issues:
    It makes it extremely difficult for the artist who creates the original animation. They can't scroll through the timeline and see what the final result looks like (like they could before the layers were converted to movie clips).
    In order to drive the animation, you have to call gotoAndPlay on each sub-movie clip, instead of just once at the root level. This can cause mistakes if one movie clip's animation is slightly different than the other's.
    I've played around with a ton of ways to do this, but nothing seems to work - either the tint ends up getting lost as the movie clip plays, or the tint sticks but the animation on the movie clip disappears.
    Some examples of the types of things that would make this possible would be being able to assign a Tint setting from the the Flash IDE to an actionscript variable that I could change dynamically, being able to apply tints to layers instead of movie clips, etc. As far as I can tell, none of this is accessible in actionscript.
    Does anyone have suggestions on how I can solve this problem, either through actionscript or by changing how the original Flash .fla is set up? To reiterate - making it so the artist can easily create the animation and maintain it is a top priority.
    Thanks!

    it doesn't matter what kind of loop you use as long as it
    checks frequently enough to catch the termination condition, not
    too frequently so it wastes computing resources and terminates when
    no longer needed.

  • I can not loop part of my animation. Please Help.

    Hello for the past 4 hours I have been trying to loop part of my animation. I've gone through a few tutorials step by step, but I am not getting it to work. I need the animation to loop when it is completed back to the label named "looper". I have tried adding the action to the end of the timeline, I have also tried triggers, but they all do not work. Thank you for the help.
    Here is the link to the project. https://creative.adobe.com/share/ccb48fd8-9cd8-4de4-b6b5-e2cf8ac29150

    Your link does not seem to work.
    Did you apply the principles shown in the AE sample: Creating a Loop Counter?

  • IPOD Skipping to a random part  of songs

    Hi people,
    I have a 5th generation iPod. Recently since installing the latest patch 1.2.1 I've noticed from time to time, my iPOD while playing a playlist, after completing a song will start the next song, (duh wait for for the problem ) but not from the start of it.
    I have been unable to replicate this problem so I am unsure what the cause is. Sometimes it will skip tot he middle part of a song sometimes to the end. Clicking fast forward would skip to a random part of the next song.
    Starting the song again will fix it, but I find this annoying as I turn my wheel lock on while playing.
    Anyone know what's going on?
    I have tried restoring my iPOD once but that did not fix the problem.
    Regards,
    Bobs_Pizza

    Here's how to solve this problem for ALL songs
    left click your first song [in your music library]
    now scroll down to your last song, hold shift, and left click the last song
    right click and click "get info"
    click OK after the warning message [for editing multiple files at a time]
    disable the "remember playback position" option
    connect your iPod, and this should do the trick!
    also, your iPod doesn't just remember that option from iTunes, it also remembers your EQ preset for certain songs and also volume adjustment for certain songs [-100% to +100% in case the song is too loud]

  • Flash looping second part of the animation ?

    Hey.
    I'm fairly new to Flash and I'm not familiar with it's functions.
    The animation I made in Maya is in 2 parts. For The second part of the animation I want it to be looping. The first part no.
    How can I make this.
    Thank you

    How is your animation currently arranged in Flash?  If it is purely a single timeline animation, then in the last frame of the second animation you would use actionscript:
    gotoAndPlay(#);
    where # is the frame number where the second animation begins.

  • Can't get the random part of the rotation

    I'm trying to get a movie clip to start at a random rotation
    when you click on a button. I got everything to work when the
    random rotation part is not included.
    Anytime I try to include the random code I get this error:
    "1180: Call to a possibly undefined method random.

    do a search on random in help and you'll find its now part of
    the Math class. Alternatively, have a look in the ActionScript 2.0
    Migration section in the Appendix, and you'll find that random()
    has been removed in AS3 and Math.random() is now used instead.
    Its used a little differently so its a good idea to look it
    up.

  • Group replica place -random parts place rotated 180

    When I do a group replica place I get parts in random groups that are placed with 180 deg rotation from the corresponding part in the reference group.
    Sometimes if I repeat the placement it corrects itself.
    Seems similar behavior has always been there.
    http://forums.ni.com/t5/Circuit-Design-Suite-Multisim/Group-replica-place-bug-w-workaround/m-p/84134...
    Also, in the replica place window my master group component list has '(Yes)' next to about 2/3 of the parts.  What does that mean?

    The key to making group replicate work correctly is to make sure the part order in group 1 is the same as group 2 in Select Group for Replicate Place dialog.  In the attached screen capture, the corresponding part for R3 from group 1 is R6, so in group 2 R6 must be on the same row as R3.
    If the components doesn't lineup correctly, you can edit the order under Edit>>Group Editor>>Part Group, use the up/down arrow on the right side to rearrange the component order.
    Tien P.
    National Instruments

  • Looping part of an animation

    I have an animation that builds to create a logo, basically
    inividual shapes fade in. Once the logo is built I would like to
    run a lighting effect at the bottom of it that will loop, but do
    not want the whole animation to start over with the loop.
    What would be the best way to go about this?
    Thanks in advance-
    nd

    ok..now....so you made the light effect, then on the last
    frame of everything, type in the code "gotoAndPlay(35);"..instead
    of the 35 type in the number of the frame were the lightning effect
    begins.

  • Why does the 'publish preview' screen in flash cs5 show part of the animation and then turns blank?

    Hi I am creating frame by frame animation in photoshop.
    I am importing the photoshop files into flash using
    FILE > IMPORT > IMPORT TO STAGE
    I used to be able to preview or "line test" my animation easily by clicking on:
    FILE > PUBLISH PREVIEW > FLASH
    I could watch the animation loop and see where improvements are needed. Now, flash struggles a lot with the files, takes a long time to load the preview, when it finally does, it shows me maybe a third of the animation, turns blank, and acts as if all my frames are completely blank. I cannot later see them on my main work surface either.
    Does anyone know what is going on? I keep restarting flash but the same problem persists.
    Thanks in advance for any help or suggestions

    Hi,
    Thanks, that might be it, I will look at re-sizing.
    I'm working in a very round-about way, of creating the frame by frame animation in photoshop, importing it to flash for preview, exporting from flash as png sequence into after effects where I continue animating.
    So I will look at exporting the png sequence straight from photoshop - let's see how this goes
    Thanks,
    W.

  • How to trigger an event after symbol animation completes?

    Hello,
    I have been trying to figure this out without success.
    On the stage I have a button and a hidden symbol. The symbol has an animation within itself.
    When I click the button, the symbol becomes visible and plays the animation. Its all good so far.
    This is what I am trying to accomplish:
    I want to be able to click the now visible symbol, the animation within itself plays in reverse and then it hides itself.
    How do I make it hide itself after the animation plays in reverse?
    ==================================================================================
    BUTTON CODE (This works for me):
    sym.$("AnimationOne").show();
    var AnimOne = sym.getSymbol("AnimationOne");
    AnimOne.play(0);
    SYMBOL CODE (This needs to hide after animation ends):
    var AnimOne = sym.getSymbol("AnimationOne");
    AnimOne.playReverse();
    sym.$("AnimationOne").hide(); // If I add this, it just hides itself without animating in reverse
    ==================================================================================
    Thank you in advance for any help/suggestions.

    simple work around:
    place a label on your symbol and turn visibility ON
    Then on compostion ready stop your symbol on that label
    var s = sym.getSymbol("shape");
    s.stop("startAni");
    On your click event play the symbol from the label.
    var s = sym.getSymbol("shape");
    s.play("startAni");
    Then on your playReverse it will go all the way to 0 where visibility is OFF.
    sample here:
    https://www.box.com/s/m6zm1lt49bl74iwpva9l

  • Trigger an Adobe Edge Animate animation when entering the screen

    Playing an animation when entering screen would be nice...

    Hello Carpe,
    You can insert an animation file in the start page of a site. More details about integrating Edge contents in Muse here:
    http://www.adobekb.com/inserting_edge_content.html
    http://www.youtube.com/watch?v=fps_oeMmywA
    Hope this helps.
    Cheers
    Parikshit

  • Ipod playing at random part in song after on pause

    I pressed pause on my ipod and came back to it about 1/2 an hour later. I pressed play and it started playing somewhere different in the song! Near to the start, but not at the start!
    I just updated my software-however I updated it while the ipod was plugged in...maybe I should not have done that?

    It's possible that you triggered the touchpad to do something while you had it in your pocket. I can work all the controls on my 5th gen unit through the fabric of every pair of slacks I've tried it with. (I also have a hard plastic case that covers the whole thing except the ports and click wheel, which makes it easier to do things by feel.)

  • Load only a part of the animation

    Sometimes flash websites are really big and it's not necessary to load everything at the beginning. For example, it sounds stupid to load every photos at the beginning because most of users will only see a few pics and the others won't want to wait minutes to load a website. So I'm wondering if it's possible in catalyst to load only the structure at the beginning and then load the rest when the user need it.

    For some reason, my problem is solved!
    When I set up my Apple TV, I updated the firmware, but a few hours later another update was available. And that did the trick!

  • How to export only part of animation?

    In the case of a big animation (tens of thousands of frames), is there a way to render (using Export Movie) only part of the animation, e.g. frames 100-500 and nothing more? That way, loss of time would be reduced.

    Playing around with this a bit I found another method in addition to the one you described. I found I can mark part of the sequence with the work area bar and then use Export. The Export screen has an option to send the entire sequence or only the part under the work bar. Then I imported it into Encore and since it was exported with final disc settings Encore didn't have to encode it.
    But I think I will send in a feature request. Hopefully a lot of other people will also ask for this.
    Thanks
    Steve

Maybe you are looking for

  • Mid 2009 applecare logic board and battery ADVICE

    returning mac OS and mac hardware buyer here. i have been questioning (read complaining) about the battery life (1 1/2 hours on safari) and the performance (spinning beachballs on startup, on wake and on starting safari among other things) since i bo

  • This is crazy ADC-VGA

    This is getting nuts, no one makes an adaptor from ADC to VGA anymore? The last known one by Dr. Bott is no more. Are we stuck with using a Apple monitor on the ADC port? Grrrr.... Brian

  • Table on a curved path

    I'm trying to make a table on a curved path like this: Intuitively, I create my curve, I choose type on path tool, and once I have the type cursor blinking on my path I select Insert table. No matter how small I make the table, i.e. 2 rows, 1 colum,

  • Where we have to enter service master in sales order

    Hi guys, This is Emmanuel SD consultant, where we have to enter service master in sales order. If possible please help

  • BGP Multi-Instances

    Hi All The feature BGP Multi-Instances seems to be supported since XR 4.2.x on ASR9k. Unfortunatly there is no specific feature description included in the  configuration guides. Could anyone of the XR cracks help out with more specifics about this f