Flash, SnowFlake

I have this actonscript code that i am developing in flash cs4 for a snow storm and I cannot seem to get it to work. I found the code on the net this is the address http://www.kirupa.com/developer/flashcs4/falling_snow_as3_cs4_pg1.htm  I am not sure what the problem is.

package
{
import flash.display.*;
import flash.events.*;
 
public class Snowflake extends MovieClip
{
private var xPos:Number = 0;
private var yPos:Number = 0;
 
private var xSpeed:Number = 0;
private var ySpeed:Number = 0;
 
private var radius:Number = 0;
 
private var scale:Number = 0;
private var alphaValue:Number = 0;
 
private var maxHeight:Number = 0;
private var maxWidth:Number = 0;
 
public function Snowflake()
{
SetInitialProperties();
}
 
public function SetInitialProperties()
{
//Setting the various parameters that need tweaking
xSpeed = .05 + Math.random()*.1;
ySpeed = .1 + Math.random()*3;
radius = .1 + Math.random()*2;
scale = .01 + Math.random();
alphaValue = .1 + Math.random();
 
var stageObject:Stage = this.stage as Stage;
maxWidth = stageObject.stageWidth;
maxHeight = stageObject.stageHeight;
 
this.x = Math.random()*maxWidth;
this.y = Math.random()*maxHeight;
 
xPos = this.x;
yPos = this.y;
 
this.scaleX = this.scaleY = scale;
this.alpha = alphaValue;
 
this.addEventListener(Event.ENTER_FRAME, MoveSnowFlake);
}
 
function MoveSnowFlake(e:Event)
{
xPos += xSpeed;
yPos += ySpeed;
 
this.x += radius*Math.cos(xPos);
this.y += ySpeed;
 
if (this.y - this.height > maxHeight)
{
this.y = -10 - this.height;
this.x = Math.random()*maxWidth;
}
}
}
}
fireandice68Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
nycynikConnect With a Mentor Commented:
in your fla, you must set the class.

To do that, save the file, with the name "Snowflake.as"

Then open the fla, and in the properties, fine the box for "Class"

Enter "Snowflake" - note that there is no .as, remove that part, its the name of the class, not the name of the file.

Thats will link the class file in.
0
 
nycynikCommented:
what error do you get when you compile or run it, or why does it not work?
0
 
nycynikCommented:
So i used the code, works fine for me.

I added some snowflakes to the stage, and then attached this code, and it moves from top to bottom, kind of like snowflakes would.

--

That said, you probably want to attach this code only to some movie-clip, not to the entire stage, so that the snow moves, and the snowman stays in place.

The best way to do that is make a snowflake class, and attach this as the main function of the snowflake class, and then add snowflakes to the stage.

Another way, is to do what I did here, but this is only if you have just one snowflake.  Add the snowflake to the stage, click f8 to convert to a symbol, type the instnace name "Flake", save everything, and run it.

package 
{ 
import flash.display.*; 
import flash.events.*; 
  
public class Brix extends MovieClip 
{ 
private var xPos:Number = 0; 
private var yPos:Number = 0; 
  
private var xSpeed:Number = 0; 
private var ySpeed:Number = 0; 
  
private var radius:Number = 0; 
  
private var scale:Number = 0; 
private var alphaValue:Number = 0; 
  
private var maxHeight:Number = 0; 
private var maxWidth:Number = 0; 
  
public function Brix() 
{ 
SetInitialProperties();
} 
  
public function SetInitialProperties() 
{ 
//Setting the various parameters that need tweaking 
xSpeed = .05 + Math.random()*.1; 
ySpeed = .1 + Math.random()*3; 
radius = .1 + Math.random()*2; 
scale = .01 + Math.random(); 
alphaValue = .1 + Math.random(); 
  
var stageObject:Stage = this.stage as Stage; 
maxWidth = stageObject.stageWidth; 
maxHeight = stageObject.stageHeight; 
  
Flake.x = Math.random()*maxWidth; 
Flake.y = Math.random()*maxHeight; 
  
xPos = Flake.x; 
yPos = Flake.y; 
  
Flake.scaleX = Flake.scaleY = scale; 
Flake.alpha = alphaValue; 
  
this.addEventListener(Event.ENTER_FRAME, MoveSnowFlake);
} 
  
function MoveSnowFlake(e:Event) 
{ 
xPos += xSpeed; 
yPos += ySpeed; 
  
Flake.x += radius*Math.cos(xPos); 
Flake.y += ySpeed; 
  
if (Flake.y - Flake.height > maxHeight) 
{ 
Flake.y = -10 - this.height; 
Flake.x = Math.random()*maxWidth;
}
}
}
}

Open in new window

0
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
fireandice68Author Commented:
nycynik:
there is no error code the snow flake will just not move as it should
0
 
nycynikCommented:
so the code moves one mc from top to bottom, slowly, at various sizes (at random).

Works good for me, looks like snow.  Moves a little slow I guess, but it works.
0
 
nycynikCommented:
Is it that you just dont have the snowflakes?

Make sure the graphic of the snowflake is a movie clip.  Click on the graphic, hit f8 to convert it, and make sure the drop down shows moveiclip.
0
 
fireandice68Author Commented:
Yes I made it a movie clip right from the start mmmm just not sure it might be that the .as file is in the wrong place I have it in a folder is that right or should it be in the same location as the .fla file
0
 
fireandice68Author Commented:
Thx I have it working now, I deleted it from
My computer and started again and put it all in the same directory and it works
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.