PDA

View Full Version : SwapDepth help needed.



upuaut8
April 12th, 2002, 08:37 AM
Ok, I've got a guestbook made in flash that I just can't quite get right. If someone seriously thinks that they can help, I'd apreciate greatly.

What's going on here is that I've temporarily set up the variables from a php script into a hub clip in the upper left corner. Mind you, that's not the problem.

I have a Movie clip called page, which contains another movie clip called "entry", with an instance name of "entry".

When the movie is ready to do it's stuff, it attaches page onto the main timeline calling it page0

It then duplicates it a number of times equal to number of rows it received from the variables that are getting loaded into it (-1 for the first one on page0). (for experimentation I've placed 3 fau entries into the hub.)

So I've got three movie clips of a page, instance names "page0", "page1", and "pag2". These are located at a depth of 400, 401, and 402 as I wanted them out of the way of anything else. Each of these pages has an entry clip in it which has been given it's variables from the hub clip back on frame 4.

Now inside page, there is a tween in which the entry turns, like a page in a book, from right to left, spanning upwards a little for effect. In the middle of it's movement, when it is almost vertical, it sends the playhead of entry to frame 2 which is blank. (tricky.. so it looks like it's only on one side:) ) Just in case you look at the file and see that, that's what it is.

Likewise when the page reaches this apex, it calls out to a function called
swap(direction);
which is supposed to take the page that is turning forward, and swap it to the bottem of the stack of "page"s. It also has animation for the other direction, calling the page to be placed on the top of the stack when it is turning from left to right.

The effect is screwed up somehow and I'm having trouble peicing it together.

I think that my method of stacking the movie clips is inferior. Especially I'd like Pom or Suprabeener to take a look, and I don't want to post it just for anyone to have. If you seriously think that you can figure out the problem then reply and I'll email the file to you.

sinfiniti
April 12th, 2002, 11:45 AM
you can use swapDepths(nNumber) where 'nNumber' is not necessarily a depth with anything on it. so, if your depths are 400, 401, and 402 and you want to place the movie from depth 401 on the top you can do 'swapDepths(403);'. if you wanted to send it behind, just do 'swapDepths(399);'.
you could also create a function that would sort all the 'pages' at the same time.
example:
function fSortDepth(aMovies,aDepths){
// 'aMovies' is an array of references to movies.
// 'aDepths' is a corresponding array of depths.
for(ii=1000;ii<aMovies.length+1000;ii++){
// move the clips to depths that are out of the way.
aMovies[ii].swapDepths(ii);
}
for(ii=0;ii<aMovies.length;ii++){
// move the clips to the depths where they belong.
aMovies[ii].swapDepths(aDepths[ii]);
}
}
// so, to call this function:
aClips=[_root.mcPage0,_root.mcPage1,_root.mcPage2];
aOrder=[403,401,402];
fSortDepth(aClips,aOrder);
// that will put the clips in this order:
// _root.mcPage1 - depth of 401
// _root.mcPage2 - depth of 402
// _root.mcPage0 - depth of 403

hope that helps!
:)
jeremy

p.s. that function is scalable so you can have as many clips as you want.

upuaut8
April 12th, 2002, 01:44 PM
I could try running it that way. I'll give it a shot. At this point I'm ready to try anything

suprabeener
April 12th, 2002, 01:59 PM
i've had similiar troubles. i ended up writing a few methods that will manage the depths for you ... basically create a _depth property.

i've put that here:
members.shaw.ca/rlinton/eg/depths.html (http://members.shaw.ca/rlinton/eg/depths.html)

it's not very pretty ;), but it shows you how it works.

click the square to create a movie, then you can drag them about, move them down or up a level, or move them to the bottom or top.

you can see the stack on the left.

mind you, mx has now made it possible to query a movie as to its depth. there's still a few abilities that these methods add; you can move a movie to a depth (vs swapping a movie's depth), and you can ask what movie is in a particular depth.

you have to be careful not to adjust the depth or add movies without using the functions though, otherwise they get out of synch and the whole thing falls apart. as long as you stay within the framework though, it works great!

sinfiniti
April 12th, 2002, 03:02 PM
here's a one-liner for ya:
MovieClip.prototype._depth = function (nArgs) { this.swapDepths(nArgs);};
then, to set a movie clip's depth:
_root.mcMovie._depth(nNumber);
where 'nNumber' is the desired depth.
:)
jeremy

upuaut8
April 13th, 2002, 02:03 AM
wow

I have a couple of functions that I had writen to take care of this stuff.. but I must admit this script is very nice.

I had origionaly been working with a depth array, but couldn't get it to work correctly. I think that this will help me very much. Thank you.

If I have a question on this I'll post back here.

suprabeener
April 13th, 2002, 02:56 PM
sin,

you may as well write:

MovieClip.prototype._depth = MovieClip.prototype.swapDepths;

but then, why bother? aside from saving a few keystrokes, i don't see an advantage.

sinfiniti
April 13th, 2002, 04:54 PM
i didn't see the advantage either, that's why i wrote the function above. i'm all about saving keystrokes though!
:)
jeremy

suprabeener
April 13th, 2002, 05:23 PM
no, i mean why bother writing the function at all. : )

since it just creates another way to call swapDepths.

sinfiniti
April 13th, 2002, 11:32 PM
no, the other function up there!! farther up!
:)
jeremy

ilyaslamasse
April 14th, 2002, 07:22 AM
In French, we call this un dialogue de sourd :lol:
pom 0]

upuaut8
April 15th, 2002, 03:58 AM
Thank you sooooo much Supra. You're code is a dream of functionality.

I'm using sections of it and changing them around for my usage... I almost had the whole thing completed when what should I see.. but the page turning example in the Flash 5.0 forum ... now I have to remake my animated pages to be at least that good.

Ah well.. still working on it. Thanks for all the help.

suprabeener
April 15th, 2002, 01:25 PM
upuaut - thanks. long live oop!

sin - gotcha, that makes sense now. : )