PDA

View Full Version : Major Problems with Depth and Components


Veleek
11-22-2005, 11:17 PM
Difficulty with depth problems.

First of all, I'd just like to say that even though this code is quite simple, it's causing me a huge load of problems and I'm not new at Actionscript. Please if you have any suggestions one what I can do to solve this problem I would GREATLY appreciate it. Throw whatever you've got at me. I don't care how technical it is.

The output of the following code differs depending on one thing. Whether or not I have on the basic UI Components in my Library (not necessarily on the stage). Code below is that I'm doing:

var d:Number = getNextHighestDepth();
trace("Depth: " + d);
attachMovie("ball_mc","b",d,init);
trace("B before: " + b);
b.removeMovieClip();
trace("B After: " + b);

This code traces the following if there are NO components on in the library:
Depth: 0
B before: _level0.b
B After: undefined

If put a component on the library I get this:
Depth: 1048576
B before: _level0.b
B After: _level0.b

And if I run again with Ctrl-Enter, I get this:
Depth: 1048574
B before: _level0.b
B After: undefined

Now the problem I have is that the first time I run it, it doesn't delete b, and as this is going to be on the net, I can't expect userse to run it twice so it works. The problem appears to be that it sets the next higest depth to one higher than the max depth (defined in DepthManager.as). I'm not sure why running it again decreassing the depth value, but it keeps going down if I keep rerunning this.

This is causing me major problems when I load a template frame. Since it won't delete when I return to the page it won't initialize properly and causes problems and slowdowns if I return to the same frame too many times.

Anybody have any suggestions.

PS. I was poking around in DepthManager and DepthControl classes recently. Looking over them again, I can't seem to find anything that I may ahve accidentally changed, but that might be the problem.

Xeef
11-22-2005, 11:54 PM
Note: If you are using version 2 components, do not use this method. If you place a version 2 component either on the Stage or in the Library, the getNextHighestDepth() method can sometimes return depth 1048676, which is outside the valid range. If you are using version 2 components, you should always use the version 2 components DepthManager class.

Gibberish
11-22-2005, 11:57 PM
bah Xeef beat me. ;)

Veleek
11-23-2005, 03:11 PM
Thanks guys, havn't had a chance to fool around with this yet, but I'm assuming that will solve my problem. Just out of curiosity, where does it mention this peculiar problem? I also hadn't noticed it anywhere that when using V2 components we should use the new Manager classes.

And just for confirmation, your saying that instead of using attachMovie("ball","b",getNextHighest(),init) that I should use createChildAtDepth("ball",DepthManager.kTop,init). Correct?

Xeef
11-23-2005, 07:36 PM
the text from me is out of the MM help (getNextHighestDepth)

createChildAtDepth("ball",DepthManager.kTop,init)

Hmmm i dont have much expiriece whit this

but i think it's better to use some depth for creating objects and the SWAP it whit the DepthManager

kTop is always 201 or so and if you have it 2 after each you over write the first

(but i coud by wrong)

dotlingo
07-05-2006, 02:37 AM
Hi,

We had the same problem as you guys so we made a _global function that fixed everything for us, works the same as the getNextHighestDepth() function should work ;-)

1.
Create a file named 'getRealDepth.as'.


2.
Copy and paste the following code into 'getRealDepth.as'...

//Code created by someone annoyed by the getNextHighestDepth function
at 4.44am!

_global.getRealDepth = function(level){
if(eval(level).realDepth == null){eval(level).realDepth = 0;}
else{eval(level).realDepth+=1;}
return eval(level).realDepth;
};

//


3.
In the first frame of your main fla add the following line of code...

#include "getRealDepth.as"


4.
Instead of using 'getNextHighestDepth()' all you do now is use is...

getRealDepth(level);

Replace 'level' with the object/level you are referencing - for example
MC, this, _root.


5. This solves all of our depth problems in Flash without using a lot
of code and also seems logical.

If you get any problems post back.

I hope this helps ;-)

Dotlingo.

dotlingo
07-05-2006, 06:35 PM
*Please note*

I posted the wrong script last time, I used the old .as file by mistake.

The actual code for 'getRealDepth.as'... is....

_global.getRealDepth = function(level){
if(eval(level).realDepth == null){eval(level).realDepth = 1;}
else{eval(level).realDepth+=1;}
return eval(level).realDepth;
};

lizsterine
10-14-2006, 07:16 AM
Thanks dotlingo! Good effort. I just came across the same issue with getNextHighestDepths and components, and your little function saved my a*s ;)

Gotta love quick solutions so close to deadline time.

Thansk again! :D

Rossman
11-02-2006, 08:14 PM
If you are using version 2 components, you should always use the version 2 components DepthManager class.

Does anyone know how to do this properly?

Currently I am creating a combobox and a datagrid, but the damn combobox drop-down is always z-indexed behind the datagrid.

I have tried setting depth's normally, as well as attempting to use the DepthManager, but with no success.

Please help!

Elz
04-27-2007, 09:46 AM
Okay I was having this probelm and discovered this thread. Can anyone, as Rossman asked, show or point the way towards a solid example of the proper use of DepthManager?

Now in my case, I've got a shared library with hundreds and thousands of lines of shared code in it. Of course when I added v2 components to this library, i noticed the error caused by the maxed-out depth.

There are a lot of flash apps deployed already that use this library at runtime. Even if i created an additional library with the v2 components just for new apps that need them, is it actually the case that I have to go through the hundreds of lines of shared code and change/remove all uses of getNextHighestDepth()!?!? :(

Can someone please enlighten me.

spectacle
11-02-2007, 04:52 PM
Hi all,

I had the same problems with these levels. What I wanted to do was creating and destroying a Combobox 'TeamList' on the fly:

Destroy the combobox if it exists
Make a new combobox

I used the levelscript from this page. This didn't work however. The second time I created a combobox, it did not work correctly. the depths returned by the scipts were really stragne as well. I found out that this does not work:

destroyObject('TeamList');
_level0.createClassObject(mx.controls.ComboBox, "TeamList", getRealDepth(_level0));

The second time you do this, levels of around -32773 are returned by the script.

Apparently it takes time to destroy is, because what does work, is having createClassObject called by a interval function. Even with 20 ms it works out fine. What would be better is that destroyObject would give back something if it succeeds, but it does not.

I'm pretty sure this is the same for all level 2 components. (?) Forgive me though. I'm back Flashing since I left using Flash 4. LOL

Sorry that the naming of the ComboBox is not variable (it's always 'TeamList') The functions could off course take name, type and data as arguments...



Paste this example in frame 1 to see what I mean:

///////////////////////////////////////////////////////////////////////

var intervalDelay:Number=20;


_global.getRealDepth = function(level) {
if (eval(level).realDepth == null) {
eval(level).realDepth = 1;
} else {
eval(level).realDepth += 1;
}
return eval(level).realDepth;
};

function ComboDelay() {
clearInterval(ComboIntid);
CreateCombo();
}



//destroy combobox
function KillCombo() {
destroyObject('TeamList');
}

//create combobox and fill
function CreateCombo() {
_level0.createClassObject(mx.controls.ComboBox, "TeamList", getRealDepth(_level0));
trace("Depth : "+TeamList.getDepth());
var myDP_array:Array = new Array();
myDP_array.addItem({label:"Option 1", data:0});
_level0.TeamList.dataProvider = myDP_array;
}

//delete
var buttonListener:Object = new Object();
buttonListener.click = function(evt_obj:Object) {
KillCombo();
};

//delete and make, delayed WORKS JUST FINE
var button2Listener:Object = new Object();
button2Listener.click = function(evt_obj:Object) {
KillCombo();
_level0.ComboIntid = setInterval(_level0, "ComboDelay", _root.intervalDelay);
};

//delete and make immediatly DOES NOT WORK!!!
var button3Listener:Object = new Object();
button3Listener.click = function(evt_obj:Object) {
KillCombo();
CreateCombo();
};

//make items
this.createClassObject(mx.controls.Button, "my_button", getRealDepth(_level0), {label:"Delete"});
this.createClassObject(mx.controls.Button, "my_button2", getRealDepth(_level0), {label:"delayed"});
this.createClassObject(mx.controls.Button, "my_button3", getRealDepth(_level0), {label:"immediately"});
my_button.move(TeamList.left, 50);
my_button2.move(TeamList.left, Stage.height-my_button.bottom);
my_button3.move(TeamList.left, Stage.height-my_button2.bottom);

//Add Listener
my_button.addEventListener("click", buttonListener);
my_button2.addEventListener("click", button2Listener);
my_button3.addEventListener("click", button3Listener);




//CreateCombo();

Rossman
11-02-2007, 09:27 PM
Apparently it takes time to destroy is, because what does work, is having createClassObject called by a interval function. Even with 20 ms it works out fine. What would be better is that destroyObject would give back something if it succeeds, but it does not.

When working with components: "When in doubt, wait a frame."
Sometimes it will take an additional frame processing time to actually create or destroy a component. Your 20ms delay is, in effect, waiting a frame, allowing Flash enough time to destroy the component.

spectacle
11-03-2007, 12:01 AM
When working with components: "When in doubt, wait a frame."
Sometimes it will take an additional frame processing time to actually create or destroy a component. Your 20ms delay is, in effect, waiting a frame, allowing Flash enough time to destroy the component.

Yeah, I guess that must be it. I never worked with components. I'm from the tellTarget("/") era... :)

I made a script which builds elements according to an XML file and the entire script is in the same frame. Every next node, all created elements are destroyed and recreated when necessary. This timing becomes a problem when working this way. I wish I knew that this morning. :(

Well, it works now. I hope other people will learn from my mistake. I guess I'm not the first stumbling over this peculiarity of Flash.

Rossman
11-03-2007, 12:03 AM
Yeah, quite frankly, in my experience you are better off avoiding the components altogether, and building your own from scratch. While the components do work fairly well, they are a major pain to skin, and they are slow as hell to create/destroy.

spectacle
11-03-2007, 12:15 AM
I guessed they would prove to be a time saver. and they do in fact work quite well, especially those like the ComboBox. I for one would have to think for a while how I would make such a thing. But then again I made these thing with nested movieclips (remember those?).

You're right though, they are slow, not easy to customize and it's a lot of KB's for what you get in return...

Well.. it works now. Weekend ;)

spectacle
01-16-2008, 05:31 PM
I stumbled upon another strange behavior. If you destroy the box with actionscript while the menu is open (you clicked the combobox), you could (?) get the result that the box is destroyed, but the menu remains on the screen, even though debug > list objects does not list the object. You can still browse through the items though. Very strange indeed.

A solution is:

Selection.setFocus('SomeOtherObject');
destroyObject('ComboBox');

This eliminates the 'ghost' menu problem