Alpha and Scale Particle Properties - Flash CS3
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.
Editor's Picks Articles
Top Ten Articles
Content copyright © 2019 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.