Skip to main content
Participant
July 10, 2009
Answered

Problem with swapdepth on buttons

  • July 10, 2009
  • 1 reply
  • 1823 views

Here is the situation. I am attempting to make a simple web navigation bar. I have two buttons that are overlapping each other. On the rollover I want the button that is in the back to be brought to the front. this is the script I have.

on(rollOver)

{
    tips_btn.swapDepths(home_btn.getDepth() + 1);
}

I have used trace to see what level they are on before and after but the numbers never change. Both always stay at the same level. This should be something simple and I am probably just overlooking something. Any help would be greatly appreciated, thanks in advance.

This topic has been closed for replies.
Correct answer Ned Murphy

I really truly do appreciate your help. I made an attempt to set mine up like the example you gave me and yet I must still be missing something because it still isn't responding. I uploaded it to http://web.ics.purdue.edu/~efrazee/cgt141/project1/test1.fla if you could take a quick look that would be fantastic.

Edmund


You don't have the instance names assigned to the movieclips.  The names you assign in the library are not the instance names.  Instnce names are assigned in the properties panel.  That allows you to reuse the same library item multiple time because you can assign it different instance names.

1 reply

Ned Murphy
Legend
July 10, 2009

If kGlad or someone else who might know comes along, maybe some light can be shed on this, but here's what I found.  I couldn't get the swapDepths method to work for Button symbols, but I could get it to work for MovieClip symbols using timeline coding.  I changed both items to MovieClips and used the code shown below.  The same code wouldn't work for them as Button symbols, so it may just be a MovieClip method (much like gotoAndPlay is not associated with buttons)

tips_btn.onRollOver = function(){
tips_btn.swapDepths(home_btn);
}

Inspiring
July 10, 2009

For some very strange reason they never included the swapDepths method in the Button prototype. Addding this line at the very beginning of your timeline should solve it. I hardly ever use actual button instances so I haven't used this much. I can't promise that it won't create some other problems, but it shouldn't, i.e. at least in everyday usage.

Button.prototype.swapDepths = MovieClip.prototype.swapDepths;

Of course I would really recommend not using buttons....

efrazeeAuthor
Participant
July 10, 2009

Ned:

When I convert them to movie clips the same exact thing happens as when they were buttons. There seems to be no change for me.

Rothrock:


When I toss that in at the beginning of my timeline it does some good. It brings the correct button to front however it leaves the "over" frame as well as the "down" frame there. So I get a button inside a button.

The navigation bar I am designing consists of 4 playing cards. When it loads it looks like the cards are being "breasted", or what it would look like when someone is holding cards in their hand. Then on the rollover I want the card to get bigger and come to the front. When I do what Rothrock suggested it creates the bigger card then returns to the down frame and creates that inside of it. I am not too terribly particular on how I accomplish this, I just want to be able to accomplish it whether using buttons or movie clips. My flash/actionscript skills are not only minimal but are also rusty seeing as I haven't touched flash in years. Any suggestions as to how to accomplish this?