Forum Topic: Intermediate AS question

(387 views • 13 replies)

This topic is 1 page long.

<< < > >>
None

Max-Vador

Reply To Post Reply & Quote

Posted at: 4/2/06 07:30 PM

Max-Vador LIGHT LEVEL 11

Sign-Up: 11/12/05

Posts: 122

i made a leaf generator a while back, and it just makes copies of the 2 differant leaf movieclips and randomly places them on the stage. but i have a problem with the depth, i need them to be behind everything, but if i try to change the depth variable, it gets all goofed up. it's on the lowest layer of the animation.

for (i=0; i<5; i++) {
var newleaf = leaf.duplicateMovieClip("leaf"+i, i);
newleaf._x = random(550);
newleaf._y = random(0);
newleaf.gotoAndPlay(random(25)+1);
}
for (j=i; j<i+5; j++) {
var newleaf = leafslow.duplicateMovieClip("leafslow"+j, j);
newleaf._x = random(550);
newleaf._y = random(0);
newleaf.gotoAndPlay(random(50)+1);
}


None

ssjskipp

Reply To Post Reply & Quote

Posted at: 4/2/06 07:32 PM

ssjskipp LIGHT LEVEL 14

Sign-Up: 10/16/03

Posts: 724

Why not just use this on everything else:

this.swapDepths(REALLY HIGH NUMBER)

"Give a man a match, and he'll be warm for a minute, but set him on fire, and he'll be warm for the rest of his life."


None

sosjulian

Reply To Post Reply & Quote

Posted at: 4/2/06 07:33 PM

sosjulian NEUTRAL LEVEL 11

Sign-Up: 06/14/05

Posts: 680

make a new layeron the bottom and put the as there


None

Max-Vador

Reply To Post Reply & Quote

Posted at: 4/2/06 07:34 PM

Max-Vador LIGHT LEVEL 11

Sign-Up: 11/12/05

Posts: 122

At 4/2/06 07:32 PM, ssjskipp wrote: Why not just use this on everything else:

this.swapDepths(REALLY HIGH NUMBER)

they still show up in front


None

Kirk-Cocaine

Reply To Post Reply & Quote

Posted at: 4/2/06 07:36 PM

Kirk-Cocaine EVIL LEVEL 34

Sign-Up: 08/17/03

Posts: 16,551

At 4/2/06 07:34 PM, MaxV wrote: they still show up in front

What you want do is add another var called something like dep, and use it to set the MC depth and every time it loops have it dep--

If the light is green, the trap is clean.

PSN ID: KirkNG

BBS Signature

None

Max-Vador

Reply To Post Reply & Quote

Posted at: 4/2/06 07:41 PM

Max-Vador LIGHT LEVEL 11

Sign-Up: 11/12/05

Posts: 122

At 4/2/06 07:36 PM, Mr_Chainsaw wrote:
At 4/2/06 07:34 PM, MaxV wrote: they still show up in front
What you want do is add another var called something like dep, and use it to set the MC depth and every time it loops have it dep--

like this?

dep = 999;
for (i=0; i<5; i++) {
var newleaf = leaf.duplicateMovieClip("leaf"+i, dep);
newleaf._x = random(550);
newleaf._y = random(0);
newleaf.gotoAndPlay(random(25)+1);
}
for (j=i; j<i+5; j++) {
var newleaf = leafslow.duplicateMovieClip("leafslow"+j, dep);
newleaf._x = random(550);
newleaf._y = random(0);
newleaf.gotoAndPlay(random(50)+1);
}

that still doesn't work


None

Kirk-Cocaine

Reply To Post Reply & Quote

Posted at: 4/2/06 07:44 PM

Kirk-Cocaine EVIL LEVEL 34

Sign-Up: 08/17/03

Posts: 16,551

At 4/2/06 07:41 PM, MaxV wrote: that still doesn't work

That because you've set dep at 999 and you should set it at low number if you want it to be behind stuff. Also you're making dep change as it loops.

I'm not sure if you can set var to minus numbers, but if you can that could work.

Or you set dep at 999 but then convert the items you want to be infront of the leaves to MC's and set their depths to things like 9997, 9998, 9999 etc.

If the light is green, the trap is clean.

PSN ID: KirkNG

BBS Signature

None

Max-Vador

Reply To Post Reply & Quote

Posted at: 4/2/06 09:42 PM

Max-Vador LIGHT LEVEL 11

Sign-Up: 11/12/05

Posts: 122

i thank you for your help, but it's still now working.


None

Johnny

Reply To Post Reply & Quote

Posted at: 4/3/06 05:33 AM

Johnny DARK LEVEL 20

Sign-Up: 04/17/04

Posts: 3,698

The problem isn't with your code, it's with flash.

Flash has 3 depths "areas"

the Timeline zone (depths = -16, 384 to -1)
the dynamic zone(depths = 0 to 1,048,575)
the reserve zone(depths = 1,048,567 to 2,130,690,045)

Anything you draw is instantly placed at a depth of -16,384 and goes upwards from there.

Anything added by actionscript starts at 0 and goes up from there. The only exeption to this rule is the createEmptyMovieClip method, which can.. in theory be set to a depth of -9999999999 or something crazy like that.

Without using swapDepths on the stuff ON the stage, you can't get them into the dynamic zones to allow your duplicated items to be behind the stuff you drew on stage.

There might be a workaround with creating an empty movie clip... but I haven't worked with it at all.


None

Vengeance

Reply To Post Reply & Quote

Posted at: 4/3/06 05:40 AM

Vengeance EVIL LEVEL 28

Sign-Up: 03/18/05

Posts: 5,049

well, the problem that i see is that it's using the same depths for multiple object's which screw's flash up.
_root.onLoad=function(){
previ=0
}
if(actions to duplicate){
previ+=5
for (i=previ; i<previ+5; i++) {
var newleaf = leaf.duplicateMovieClip("leaf"+i, i);
newleaf._x = random(550);
newleaf._y = random(0);
newleaf.gotoAndPlay(random(25)+1);
}
for (j=i; j<i+5; j++) {
var newleaf = leafslow.duplicateMovieClip("leafslow"+j, j);
newleaf._x = random(550);
newleaf._y = random(0);
newleaf.gotoAndPlay(random(50)+1);
}
that should work.

========|| WWWWWWWW>[-[Blog] - [Audio] - [Userpage] - [Flash] - [Last.fm]-]<WWWWWWWW ||========

BBS Signature

None

DJStatika

Reply To Post Reply & Quote

Posted at: 4/3/06 12:26 PM

DJStatika NEUTRAL LEVEL 04

Sign-Up: 04/19/05

Posts: 43

Make and empty movieclip, place it in the top left on a layer behind the other stuff, then create the leaves in that


None

Max-Vador

Reply To Post Reply & Quote

Posted at: 4/3/06 09:23 PM

Max-Vador LIGHT LEVEL 11

Sign-Up: 11/12/05

Posts: 122

At 4/3/06 05:40 AM, -Vengeance- wrote: well, the problem that i see is that it's using the same depths for multiple object's which screw's flash up.
_root.onLoad=function(){
previ=0
}
if(actions to duplicate ){
previ+=5
for (i=previ; i<previ+5; i++) {
var newleaf = leaf.duplicateMovieClip("leaf"+i, i);
newleaf._x = random(550);
newleaf._y = random(0);
newleaf.gotoAndPlay(random(25)+1);
}
for (j=i; j<i+5; j++) {
var newleaf = leafslow.duplicateMovieClip("leafslow"+j, j);
newleaf._x = random(550);
newleaf._y = random(0);
newleaf.gotoAndPlay(random(50)+1);
}
that should work.

thanks, but what do i put in the bolded part? it just makes no leaves show up.

and DJ, that doesn't work either.


None

DJStatika

Reply To Post Reply & Quote

Posted at: 4/4/06 05:17 AM

DJStatika NEUTRAL LEVEL 04

Sign-Up: 04/19/05

Posts: 43

It should work, just put this code on the first frame in the movie clip:

this.onLoad=function(){
previ=0
}
if(actions to duplicate ){
previ+=5
for (i=previ; i<previ+5; i++) {
var newleaf = leaf.duplicateMovieClip("leaf"+i, i);
newleaf._x = random(550);
newleaf._y = random(0);
newleaf.gotoAndPlay(random(25)+1);
}
for (j=i; j<i+5; j++) {
var newleaf = leafslow.duplicateMovieClip("leafslow"+j, j);
newleaf._x = random(550);
newleaf._y = random(0);
newleaf.gotoAndPlay(random(50)+1);
}


None

Vengeance

Reply To Post Reply & Quote

Posted at: 4/4/06 05:32 AM

Vengeance EVIL LEVEL 28

Sign-Up: 03/18/05

Posts: 5,049

At 4/4/06 05:17 AM, DJStatika wrote: It should work, just put this code on the first frame in the movie clip:

no silly, maybe you shouldn't give advice about other people's script's. it goes on the frame.
if(actions to duplicate ){
that is what you have to change in the script. maybe to if(Key.isDown(Key.SPACE)) or whatever you want, a boolean. your choice.

========|| WWWWWWWW>[-[Blog] - [Audio] - [Userpage] - [Flash] - [Last.fm]-]<WWWWWWWW ||========

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 01:16 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!