PDA

View Full Version : Actionscript anim not affected by layer order


skerm
02-24-2006, 10:51 PM
HI, new to flash, new to actionscript and new to this forum so sorry for the noobishness ;)

I've been experimenting with actionscript and I have created a "window" on a layer and created another layer with a "snowing" actionscript, the idea being that the viewer is looking out from the inside of a house and it is snowing outside. My problem is that the snow animation doesn't care about layer ordering on the timeline and hence i get snow all over the place when i just want it to be "behind" the window frame so to speak.

I suspect it can have something to do with the _root thing but I really don't know. If someone could explain this to me I would be very grateful. Here is the code (from some tutorial).


var swidth = 550;
var sheight = 400;

// movieclip to hold our 'drops'
_root.createEmptyMovieClip("DropClip", 15999);

// setup the screen initially so it doesn't start empty
for(var i=0; i<50; i++)
{
createdrop(random(sheight));
}

// create our interval
var lightstorm = setInterval(createdrop, 100);

// our function which creates a rain/snow drop
function createdrop(y)
{
var clip = "drop" + Math.random();
_root.DropClip.attachMovie("Drop", clip, random(15999));
_root.DropClip[clip]._x = random(550);
if(y != null)
{
_root.DropClip[clip]._y = y;
}

_root.DropClip[clip]._alpha = random(100);
_root.DropClip[clip].speed = random(4);
_root.DropClip[clip].onEnterFrame = fall;
}

// our onEnterFrame function is what makes the drops
// move. we check if we can remove a clip if it's outside
// the stage, otherwise we increase the _y position
// of the drop.
function fall()
{
if(this._y < sheight)
{
this._y += 1 + this.speed;
}
else
{
delete this.onEnterFrame;
this.removeMovieClip();
}
}

And there is a movieclip called Drop (just a small circle) in my library. Any ideas on how to make the "snow" appear behind another layer so that it doesnt cover the entire movie screen?

Thanks

/skerm

astgtciv
02-24-2006, 11:07 PM
Indeed, the actionscript doesn't care which layer it is placed in (in terms of depth). What you can do (as you suspected ;)) is (e.g.), to create an empty movieclip instance (create a new movieclip and call it "outside") on a layer which is lower than your "window" graphic. Give the instance of the "outside" movieclip an instance name (you can call "outside" as well), and then use "outside" everywhere where you use "_root" right now in your code. This will create the whole animation inside the movieclip "outside", and since its depth will be lower than that of the "window" movieclip, you should be seeing your snow "through" the window.

Here's an in-depth (yes :)) tutorial on depths by senocular: http://www.senocular.com/flash/tutorials/depths/ that you might find helpful.

skerm
02-25-2006, 12:06 AM
Thanks for your help! I did just what you said and now I have snow "outside" hehe. One thing I noticed though is that the position of the blank movie clip I created affects the position of the actionscript animation. Am I right in saying that, say the "dummy movieclip" at coords x=200 y=300 will correspond to x = 0, y = 0 for the actionscript? I.e. the child is dependant on the coordinates of the parent so to speak?

astgtciv
02-25-2006, 02:27 AM
Yes, exactly. The child movieclip has its own coordinate space - which from its point of view always starts at the origin of (0,0). But that movieclip, with everything in it, can be moved - changing the position of everything inside.

skerm
02-25-2006, 03:51 AM
Thanks alot! I'll be back with more queries when I get stuck somewhere else ;)