Working with movie clips as 'windows'

  • fido_glc
  • Newbie
  • Newbie
  • fido_glc
  • Posts: 7

Post 3+ Months Ago

I am working with multiple dragable movie clips that visualy are different windows. How can I make the selected 'window' to be on top of the others ? I don't want the code, I only need the ideea.
Firs of all, I have used depths: Every selected 'window' would get a higher depth and consequently be on top of the others. But there is a limit of depths, altough nobody will ever get there, the limit is over 1 million. Nevertheless, this is not a fullproof method.
I also thought to use only a number of depths and swap all the windows through these depths, hierarchical, the selected window havind the highest depth(my current pick). This is much more complicated that the first choice. Is it worth doing considering that the first method only breaks down at over 1 million depths ?
How does Windows and all the programs treat this problem ?
And if you have any other ideas post them here.
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

oh my, i ran into that problem some time ago.
But it's simply enough on how to do it.
let's say you have 10 windows.
Create an empty movie clip above the last window (read: with higher depth than the last window), and name it mcSwapper.
Then, when you wan to activate a window, just swapDepths.
mcWindow1.swapDepths(mcSwapper);
this will interchange the depths. If initially mcWindow1 had depth 100 and mcSwapper had depth 200, it will make mcWindow1 depth to become 200 and mcSwapper depth to become 100.
Next, when you want to make another window active, change again the current mcWindow1 depth with mcSwapper depth (this will make mcSwapper depth back to 200), and then change the new mcWindow with the mcSwapper.
so, it will be just a simple function:
Code: [ Select ]
function BringToFront(newActiveWindow)
{
    if (currentActiveWindow != undefined)
       currentActiveWindow.swapDepths(mcSwapper); // make highest depth again for mcSwapper
    newActiveWindow.swapDepths(mcSwapper); // swap depths
    currentActiveWindow = newActiveWindow; // make the new window the current active window
}

// then to set an active window:
BringToFront(myWindow);
  1. function BringToFront(newActiveWindow)
  2. {
  3.     if (currentActiveWindow != undefined)
  4.        currentActiveWindow.swapDepths(mcSwapper); // make highest depth again for mcSwapper
  5.     newActiveWindow.swapDepths(mcSwapper); // swap depths
  6.     currentActiveWindow = newActiveWindow; // make the new window the current active window
  7. }
  8. // then to set an active window:
  9. BringToFront(myWindow);
  • dann_the_van
  • Novice
  • Novice
  • dann_the_van
  • Posts: 23
  • Loc: South Wales, UK

Post 3+ Months Ago

I'm working on a project like this, that pops up 'x' amount of windows which are all draggable, changes height etc. i've used a far simpler code, that uses a _root.variable++ to increase the swapdepths.

But here's my problem, i can click the windows' buttons even when it is not the heightest point. If i put a window behind another, and put my cursor over the lowest window's close button, i can still click it!
I'm looking to only control the highest level.

should i use a 'true' statement, or just call what is currently the highest level and compare it to the windows depth!?

Thanks,
Danny
  • fido_glc
  • Newbie
  • Newbie
  • fido_glc
  • Posts: 7

Post 3+ Months Ago

To: IceCold

This is not quite right.
Say we have 3 windows: window1 at depth 100, window2 at depth 200 and window3 at depth 300. If I select window1 it will come in front of the others 2 at the depth of mcSwapper. When I select say window3 it will come in front of the others 2 but window1 will go back at 100 beyond window2. So the previous selected window will go back beyond all other windows. They are not aranged in the order of their selection. This is not a big problem here but say you have 100 windows and are working with 2. You would like the previous 2 selected to be in front of all others. The first method I described is like a history state. It covers this problem but is not fullproff.
Any other ideas ?
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

it's just as easy. just think about it. Only you will need to manipulate more depths.
  • fido_glc
  • Newbie
  • Newbie
  • fido_glc
  • Posts: 7

Post 3+ Months Ago

IceCold wrote:
it's just as easy. just think about it. Only you will need to manipulate more depths.

The more windows you have the more depths you will have to manipulate. Again I give the 100 windows example.
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

of course, if you want to mantain all windows in order and bring only the selected one on top. You just swap depth of the selected window with all the windows with a higher depth. Saying you have 100 windows and you activate window 10, you swap it's depth with all the windows with higher depth ... but in order. Best will be to have the windows named: window0, window1, ... window99, and if you want to give them names, just keep a variable inside them: windowX.windowName = "something";
Code: [ Select ]
// function to re-order windows and set window 'nr' on top
function reOrder (nr:Number)
{
    var iIndex:Number;
    this["window"+nr].swapDepths(100); // put it on top
    for (iIndex=nr+1;iIndex<=100;iIndex++)
    {
        // set all the windows, including the top one, one index below
        this["window"+iIndex].swapDepths(iIndex-1);
    }
}

reOrder(10); // -> it will bring window 10 on top, all others from top one depth less.
  1. // function to re-order windows and set window 'nr' on top
  2. function reOrder (nr:Number)
  3. {
  4.     var iIndex:Number;
  5.     this["window"+nr].swapDepths(100); // put it on top
  6.     for (iIndex=nr+1;iIndex<=100;iIndex++)
  7.     {
  8.         // set all the windows, including the top one, one index below
  9.         this["window"+iIndex].swapDepths(iIndex-1);
  10.     }
  11. }
  12. reOrder(10); // -> it will bring window 10 on top, all others from top one depth less.
  • fido_glc
  • Newbie
  • Newbie
  • fido_glc
  • Posts: 7

Post 3+ Months Ago

Aha. I understand the method. Thx.

Post Information

  • Total Posts in this topic: 8 posts
  • Users browsing this forum: No registered users and 6 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.