I used some ActionScript to create a snow effect for my flash animation. Right now, the snow falls in front of my other layers, and sending to back isn't working. I'll post the ActionScript below.
I have a treeline background, with snow falling on top of that. I have pieces of a logo flying in, and I want that to be OVER the snow. Currently, when I play the animation, all I can see is the treeline and snow, and I'm guessing the logo is flying together behind it.
Can anyone be kind enough to point out how I can get this done? Thanks so much.
Snowfall ActionScript that I used (not mine) :
var snowflakes:Array = new Array();
var snowflakeProps:Dictionary= new Dictionary(true);
var max_snowsize:Number = .04;
// pixels
var snowflakesCnt:Number = 900;
var oheight:Number;
var owidth:Number;
init();
function init():void {
owidth = width;
oheight = height;
// quantity
for (var i:int=0; i<snowflakesCnt; i++) {
var t:MovieClip = new SnowFlake();//
t.name = "snowflake"+i;
t.alpha = .2+Math.random()*.6;
t.x = -(owidth/2)+Math.random()*(1.5*owidth);
t.y = -(oheight/2)+Math.random()*(1.5*oheight);
t.scaleX = t.scaleY=.5+Math.random()*(max_snowsize*10);
var o:Object = new Object();
o.k = 1+Math.random()*2;
o.wind = -1.5+Math.random()*(1.4*3);
snowflakeProps[t] = o;
addChild(t);
snowflakes.push(t);
}
addEventListener(Event.ENTER_FRAME, snowFlakeMover);
}
function shakeUp():void{
for (var i:int=0; i<snowflakes.length; i++) {
var t:MovieClip = snowflakes[i] as MovieClip;
t.x = -(owidth/2)+Math.random()*(1.5*owidth);
t.y = -(oheight/2)+Math.random()*(1.5*oheight);
}
}
function snowFlakeMover(evt:Event):void {
var dO:MovieClip;
var o :Object;
if(visible && parent.visible){
for (var i:int = 0; i < snowflakes.length; i++) {
dO = snowflakes[i] as MovieClip;
o = snowflakeProps[dO];
dO.y += o.k;
dO.x += o.wind;
if (dO.y>oheight+10) {
dO.y = -20;
}
if (dO.x>owidth+20) {
dO.x = -(owidth/2)+Math.random()*(1.5*owidth);
dO.y = -20;
} else if (dO.x<-20) {
dO.x= -(owidth/2)+Math.random()*(1.5*owidth);
dO.y = -20;
}
}
}
}
add your snow to a depth above your tree but below your logo.
var snowflakes:Array = new Array();
var snowflakeProps:Dictionary= new Dictionary(true);
var max_snowsize:Number = .04;
// pixels
var snowflakesCnt:Number = 900;
var oheight:Number;
var owidth:Number;
init();
function init():void {
owidth = width;
oheight = height;
// quantity
for (var i:int=0; i<snowflakesCnt; i++) {
var t:MovieClip = new SnowFlake();//
t.name = "snowflake"+i;
t.alpha = .2+Math.random()*.6;
t.x = -(owidth/2)+Math.random()*(1.5*owidth);
t.y = -(oheight/2)+Math.random()*(1.5*oheight);
t.scaleX = t.scaleY=.5+Math.random()*(max_snowsize*10);
var o:Object = new Object();
o.k = 1+Math.random()*2;
o.wind = -1.5+Math.random()*(1.4*3);
snowflakeProps[t] = o;
addChild(t); // change this to something like addChildAt(t,1). you need to check the depth of your tree and logo to determine where to add your snow.
// or create an on-stage movieclip that's between your tree and logo and add the snow to that movieclip, like:
// middle_mc.addChild(t);
// and there are other ways to handle this.
snowflakes.push(t);
}
addEventListener(Event.ENTER_FRAME, snowFlakeMover);
}
function shakeUp():void{
for (var i:int=0; i<snowflakes.length; i++) {
var t:MovieClip = snowflakes[i] as MovieClip;
t.x = -(owidth/2)+Math.random()*(1.5*owidth);
t.y = -(oheight/2)+Math.random()*(1.5*oheight);
}
}
function snowFlakeMover(evt:Event):void {
var dO:MovieClip;
var o :Object;
if(visible && parent.visible){
for (var i:int = 0; i < snowflakes.length; i++) {
dO = snowflakes[i] as MovieClip;
o = snowflakeProps[dO];
dO.y += o.k;
dO.x += o.wind;
if (dO.y>oheight+10) {
dO.y = -20;
}
if (dO.x>owidth+20) {
dO.x = -(owidth/2)+Math.random()*(1.5*owidth);
dO.y = -20;
} else if (dO.x<-20) {
dO.x= -(owidth/2)+Math.random()*(1.5*owidth);
dO.y = -20;
}
}
}
}
Thanks so much for replying.
Sorry, but I'm a Flash beginner and don't really understand ![]()
How can I check the depth of the tree and logo, since I didn't apply Actionscript to them?
I tried addChildAt(t,1), middle_mc.addChild(t), and an on-stage movie clip, but I'm pretty sure I'm doing it wrong.
Would you please be able to clarify?
Would posting the fla be beneficial?
Thanks a ton.
use:
addChild(your tree movieclip);
var snowflakes:Array = new Array();
var snowflakeProps:Dictionary= new Dictionary(true);
var max_snowsize:Number = .04;
// pixels
var snowflakesCnt:Number = 900;
var oheight:Number;
var owidth:Number;
init();
function init():void {
owidth = width;
oheight = height;
// quantity
for (var i:int=0; i<snowflakesCnt; i++) {
var t:MovieClip = new SnowFlake();//
t.name = "snowflake"+i;
t.alpha = .2+Math.random()*.6;
t.x = -(owidth/2)+Math.random()*(1.5*owidth);
t.y = -(oheight/2)+Math.random()*(1.5*oheight);
t.scaleX = t.scaleY=.5+Math.random()*(max_snowsize*10);
var o:Object = new Object();
o.k = 1+Math.random()*2;
o.wind = -1.5+Math.random()*(1.4*3);
snowflakeProps[t] = o;
addChild(t);
addChild(your logo movieclip);
snowflakes.push(t);
}
addEventListener(Event.ENTER_FRAME, snowFlakeMover);
}
function shakeUp():void{
for (var i:int=0; i<snowflakes.length; i++) {
var t:MovieClip = snowflakes[i] as MovieClip;
t.x = -(owidth/2)+Math.random()*(1.5*owidth);
t.y = -(oheight/2)+Math.random()*(1.5*oheight);
}
}
function snowFlakeMover(evt:Event):void {
var dO:MovieClip;
var o :Object;
if(visible && parent.visible){
for (var i:int = 0; i < snowflakes.length; i++) {
dO = snowflakes[i] as MovieClip;
o = snowflakeProps[dO];
dO.y += o.k;
dO.x += o.wind;
if (dO.y>oheight+10) {
dO.y = -20;
}
if (dO.x>owidth+20) {
dO.x = -(owidth/2)+Math.random()*(1.5*owidth);
dO.y = -20;
} else if (dO.x<-20) {
dO.x= -(owidth/2)+Math.random()*(1.5*owidth);
dO.y = -20;
}
}
}
}
My tree movieclip is named Bitmap2 and my logo movieclips (actually in 4 pieces that fly together) are Object1, Object2, Object3, and Object4.
I'm getting an 1120 error (undefined property).
Here's what I've got so far (and I apologize for any errors I'm making here, I'm a beginner) :
addChild(Bitmap2);
var snowflakes:Array = new Array();
var snowflakeProps:Dictionary= new Dictionary(true);
var max_snowsize:Number = .04;
// pixels
var snowflakesCnt:Number = 900;
var oheight:Number;
var owidth:Number;
init();
function init():void {
owidth = width;
oheight = height;
// quantity
for (var i:int=0; i<snowflakesCnt; i++) {
var t:MovieClip = new SnowFlake();//
t.name = "snowflake"+i;
t.alpha = .2+Math.random()*.6;
t.x = -(owidth/2)+Math.random()*(1.5*owidth);
t.y = -(oheight/2)+Math.random()*(1.5*oheight);
t.scaleX = t.scaleY=.5+Math.random()*(max_snowsize*10);
var o:Object = new Object();
o.k = 1+Math.random()*2;
o.wind = -1.5+Math.random()*(1.4*3);
snowflakeProps[t] = o;
addChild(t);
addChild(Object1);
addChild(Object2);
addChild(Object3);
addChild(Object4);
snowflakes.push(t);
}
addEventListener(Event.ENTER_FRAME, snowFlakeMover);
}
function shakeUp():void{
for (var i:int=0; i<snowflakes.length; i++) {
var t:MovieClip = snowflakes[i] as MovieClip;
t.x = -(owidth/2)+Math.random()*(1.5*owidth);
t.y = -(oheight/2)+Math.random()*(1.5*oheight);
}
}
function snowFlakeMover(evt:Event):void {
var dO:MovieClip;
var o :Object;
if(visible && parent.visible){
for (var i:int = 0; i < snowflakes.length; i++) {
dO = snowflakes[i] as MovieClip;
o = snowflakeProps[dO];
dO.y += o.k;
dO.x += o.wind;
if (dO.y>oheight+10) {
dO.y = -20;
}
if (dO.x>owidth+20) {
dO.x = -(owidth/2)+Math.random()*(1.5*owidth);
dO.y = -20;
} else if (dO.x<-20) {
dO.x= -(owidth/2)+Math.random()*(1.5*owidth);
dO.y = -20;
}
}
}
}
Thanks a million.
Did those steps.
Here are the errors in the order in which they appear:
| Scene 1, Layer 'Actions', Frame 1, Line 32 | 1120: Access of undefined property Object1. |
| Scene 1, Layer 'Actions', Frame 1, Line 33 | 1120: Access of undefined property Object2. |
| Scene 1, Layer 'Actions', Frame 1, Line 34 | 1120: Access of undefined property Object3. |
| Scene 1, Layer 'Actions', Frame 1, Line 35 | 1120: Access of undefined property Object4. |
| Scene 1, Layer 'Actions', Frame 1, Line 1 | 1120: Access of undefined property Bitmap2. |
right click whatever you think is Bitmap2, click convert to symbol, choose MovieClip and click ok. in the properties panel assign the instance name tree_mc.
shift-left click whatever your think is Object1,..,Object4 to select them all, right click, click convert to symbol, choose MovieClip and click ok. in the properties panel assign the instance name logo_mc.
remove the code you added and then add the following to confirm you followed the above steps correctly:
trace(tree_mc);
trace(logo_mc);
North America
Europe, Middle East and Africa
Asia Pacific