0

Today I got a problem with the bitmap data depth display in my project that runs in ActionScript 2. I was expecting for the bitmap data to display in the

_loader

container This is how these containers are build here:

this.windowContainer = _root.attachMovie("window", "container", _root.getNextHighestDepth());
this.windowContainer._x = 199.95;
this.windowContainer._y = 60.6;
this.backgroundType = this.windowContainer.createEmptyMovieClip("backgroundContainer", this.windowContainer.getNextHighestDepth());
this.backgroundType.beginFill(0xFFFFFF,100);
this.backgroundType.moveTo(0,0);
this.backgroundType.lineTo(580.3,0);
this.backgroundType.lineTo(580.3,439.2);
this.backgroundType.lineTo(0,439.2);
this.backgroundType.lineTo(0,0);
this.backgroundType.endFill();
this.backgroundType._x = -60.35;
this.backgroundType._y = -53.45;
this._loader = this.windowContainer.createEmptyMovieClip("__imageLoader", this.windowContainer.getNextHighestDepth());
this._loader._x = 50.75;
this._loader._y = 49.55;

Here what's I'm trying to do here, loading an image in the

_loader

container:

    function loadImage(pSource, pWidth, pHeight)
    {
        if (typeof (pSource) == "movieclip")
        {
            this._loader = pSource;
            this._loader._width = pWidth;
            this._loader._height = pHeight;
        }
        else if (pSource instanceof flash.display.BitmapData)
        {
            this._loader.attachBitmap(pSource,this._loader.getNextHighestDepth(),"auto",true); //for some reason, the bitmap's depth is somewhere behind every other container on where i cannot see the bitmap at all, such as the background, exitType, minimizeType, etc. Which means, again. The bitmap is literally behind every other containers [Please note that what I mean a container, is a movie clip. Sorry for the confusion.]
            this._loader._width = pWidth;
            this._loader._height = pHeight; 
        }
        else
        {
            this._loader.loadMovie(pSource);
            this._loader._width = pWidth;
            this._loader._height = pHeight;
        }
    }

Only this type of swaping depth works:

this._loader.swapDepths(_root.getNextHighestDepth());
function loadImage(pSource, pWidth, pHeight)
    {
        if (typeof (pSource) == "movieclip")
        {
            this._loader = pSource;
            this._loader._width = pWidth;
            this._loader._height = pHeight;
        }
        else if (pSource instanceof flash.display.BitmapData)
        {
            this._loader.attachBitmap(pSource,this._loader.getNextHighestDepth(),"auto",true);
            this._loader._width = pWidth;
            this._loader._height = pHeight;
        }
        else
        {
            this._loader.loadMovie(pSource);
            this._loader._width = pWidth;
            this._loader._height = pHeight;
        }
        this._loader.swapDepths(_root.getNextHighestDepth());
    }

I tried this:

this._loader.swapDepths(this.windowContainer.getNextHighestDepth());

or this:

this._loader.attachBitmap(pSource,this.windowContainer.getNextHighestDepth(),"auto",true);

but guess what? I STILL CANNOT SEE THE BITMAP DISPLAY. It's still behind everything.

What the correction should be here in this code is this. The bitmap data should display in front of every other containers such as [backgroundType]. Not be all the way behind.

3
  • Before investigating it any further, have you tried using fixed depths rather than dynamic getNextHighestDepth()? Commented Dec 26, 2024 at 10:34
  • I don't think so. Commented Dec 26, 2024 at 17:35
  • My comment got out of hand so I posted it as an answer. Please don't expect too much, as it's been decades since I last used AS2, but these things are worth trying out. Commented Dec 26, 2024 at 19:32

1 Answer 1

1

This is not the answer, but rather an explanation, what depth management in AS2 is and how to tackle (and maybe debug) it.

First, why it is such a mess? Macromedia (yes, that was before Adobe acquired it) needed to introduce scripting ability to create, copy and remove content from any given container/timeline. So, they decided to mark (to z-index) content layers with the short int (16 bit) indices to indicate, which content is over (larger index) or under (lesser index) which. They also decided to reserve the negative depth values (from -32768 through -1) to the pre-designed (and timeline-animated) content and left the non-negative values to runtime/scripted content.

You probably would need the getNextHighestDepth() method if you create an image gallery or a game with enemies and bullets and you don't exactly know/care how many things are already (or will be) attached into the given container, but personally I don't even remember using the getNextHighestDepth() method, because:

  1. If you code a fixed-type content, like interfaces and stuff, you don't really need it, you just put things on fixed-value depths like 0, 1, 2, etc., and that's it.
  2. There are other ways to keep your content organized, with Arrays, proxy container MovieClips, etc.

You will most probably be fine with something as simple as

this._loader.swapDepths(100);

which puts the _loader just above anything else you've created there.

So, let's make a simple (and somehow self-explanatory) example how the depth management operates in Flash Player. The hierarchy below shows what's inside what. The topmost objects are closer to the screen/user.

Root / Main Timeline:
    
    Sky Layer (MovieClip):
        Cloud 1
        Cloud 2
        Cloud 3
    
    Moon Layer (MovieClip):
        Moon
    
    Sun Layer (MovieClip):
        Sun
    
    Star Layer (MovieClip):
        Star 1
        Star 2
        Star 3
        Star 4
        Star 5

As it is, any cloud will always be on top of the Moon, Sun and all the stars. You can put the Sun onto depth 10000, and it will still be below any of the clouds (and the Moon whatsoever), because clouds don't z-index against the Sun directly, while the Sky Layer is above the Sun Layer.

You can still decide which cloud is closer to you, though, as clouds directly z-index against each other. In order to do so, you need to find out, which depth is the next empty one inside specifically the Sky Layer.

That might be your mistake, you are asking the wrong containers.

Again. If you want to put Cloud 3 on top, you need to ask SkyLayer.getNextHighestDepth(), not _root, nor anything else.

So, your hierarchy should be something like that

_root

    windowContainer
        
        _loader (__imageLoader)
            
            bitmap
        
        backgroundType (backgroundContainer)

which seems pretty much what you want.

So, if I were facing such a problem, I'd try the following (not exactly in the given order, but still):

  1. Replace getNextHighestDepth() with fixed values.
  2. Each time you create/attach a new object, trace(...) this object's _name, its getDepth(), its _parent._name and _parent.getDepth(). It is not impossible you create things more than 1 time and they are put on top of each other.
  3. Devise some method to pull objects on top of everything.

Something like that:

function bringToFront(target): Void
{
    // Sanity check.
    if (target == null)
    {
        return;
    }
    
    // Another sanity check.
    if (target._parent == null)
    {
        return;
    }
    
    // Some display objects, namely Button and TextField
    // do not have the .swapDepths(...) method themselves,
    // yet you CAN swap a MovieClip with them.
    
    // Get the original depth.
    var where: Number = target.getDepth();
    
    // Get the target depth.
    var depth: Number = target._parent.getNextHighestDepth();
    
    // Create a swapper.
    var dummy: MovieClip = target._parent.createEmptyMovieClip("Dummy", depth);

    // Swap these two depths.
    dummy.swapDepths(where);
    
    // We don't know if "where" is negative, so just in case...
    dummy.swapDepths(depth + 1);
    
    // Destroy the swapper.
    dummy.removeMovieClip();
    
    // Optional: you can also recursively bring
    // all of the parents to front, so you can
    // be sure that the object you want is
    // really on top of EVERYTHING.
    bringToFront(target._parent);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.