Alpha and Scale Particle Properties - Flash CS3

Alpha and Scale Particle Properties - Flash CS3
Now that we have our FlashR CS3 particle system snow scene animation polished a bit, we can concentrate on adding more interest and realism to our animation. In the last tutorial, we added some randomness to our snowflakes by using Math.random() to vary the amount of wind effect that is applied to each individual snowflake. Let's add even more interest by varying the size and transparency of the snowflake particle. After all, in real life, not all snowflakes are the same size. Also, by varying the transparency of some flakes, it will give the illusion that some of the snowflakes are farther away in the snow scene. So let's get busy.

First, we need to decide where we will put this new code. If we put it inside the snowfall function code, the size and transparency of the snowflake graphic will change every time Flash enters a new frame. This is because the snowfall function is the event handler for the ENTER_FRAME event listener. This will not give us the effect that we are looking for. We do not want the snowflake to change its appearance after it is drawn to the stage.

Our second option is to add the new code to the section that creates the snowflakes and sets the X and Y positions. Because this section of code only happens once for each snowflake, this is the place for our new code. We want the transparency (or alpha) and the size (or scale) for our snowflake to be determined only once at the time of its "creation".

The first line of new code that we will add will tell Flash to resize the snowflake to a random size between 0 and 1. The value of 0 will scale the snowflake down to nothing and the value of 1 will keep it at 100%. We will use the scaleX and scaleY properties to control the size. Why do we need to set both the X and Y scale? Imagine that we only set the X scale to 50%. Our snowflake would be half the width of the original size and still as tall as it was originally. It would no longer be a nice round snowflake. So we need to resize both the X and Y scale values.

_Snowflake.scaleX = Math.random();
_Snowflake.scaleY = Math.random();


But we still need to be sure that Flash resizes the snowflake evenly for both X and Y values. As we have the code written now, the X and Y values could possibly be two different random numbers. We want them to be the same random number. We can be sure of that by changing the code so that it sets the X and Y scale to the same random number.

_Snowflake.scaleX =_Snowflake.scaleY = Math.random();

Our second task is to change the transparency of our snowflake graphic. We will do this be setting a random value for the alpha property.

_Snowflake.alpha = Math.random();

Now let's add this code into our program and test our movie a few times. Each time, the snowflake should be a different size and opacity.

Save your snow scene as SnowScene7.fla.

Copyright 2018 Adobe Systems Incorporated. All rights reserved. Adobe product screen shot(s) reprinted with permission from Adobe Systems Incorporated. Adobe, Photoshop, Photoshop Album, Photoshop Elements, Illustrator, InDesign, GoLive, Acrobat, Cue, Premiere Pro, Premiere Elements, Bridge, After Effects, InCopy, Dreamweaver, Flash, ActionScript, Fireworks, Contribute, Captivate, Flash Catalyst and Flash Paper is/are either [a] registered trademark[s] or a trademark[s] of Adobe Systems Incorporated in the United States and/or other countries.





RSS
Related Articles
Editor's Picks Articles
Top Ten Articles
Previous Features
Site Map








Content copyright © 2023 by Diane Cipollo. All rights reserved.
This content was written by Diane Cipollo. If you wish to use this content in any manner, you need written permission. Contact Diane Cipollo for details.