Copy link to clipboard
Copied
Hi all,
I'm continuing trying to develop my little adventure game (I've used a heck of a lot of event listeners; don't shame me until I become pro).
I have a set of "itemAttach"s (circles generated in the constructor function I plan on using temporarily to "hold" items (other Children) that are found, i.e. setting the X and Y of an item to the X and Y of an itemAttach1, 2, etc.
Thing is, I have various scenes (Children that cover the entire stage) being added and removed that end up hiding the itemAttach's.
Can I use setChildIndex (perhaps when they're being generated through the array) to keep the itemAttach's above any other Child that comes or goes? Would it be better to set any other Child to just go behind the itemAttach's index number?
Any help would be appreciated. Certainly let me know if any other info is needed.
Here the AS and FLA files: https://www.mediafire.com/#is1k9b5mr9t2c
Here's the constructor array:
itemAttachArray = new Array();
for (var i:uint = 0; i<7; i++) {
var itemAttach:ItemAttach = new ItemAttach();
itemAttach.x = 50*i;
itemAttach.y = 400;
addChild(itemAttach);
itemAttachArray.push(itemAttach);
//trace(itemAttachArray);
}
Sorry, basically I think for now I'm just going to set my "scenes" to an index number of 0 whenever the function runs to add them so that they're beneath everything else. I discovered that apparently I can use setChildIndex as setChildIndex (ChildName, IndexNumber), like setChildIndex(campScene, 0). (I thought it had to be more complex than that, but this actually seems sufficient.)
Just me being an noob.
Copy link to clipboard
Copied
You can just use addChild() to place an object above any others. One thing you might consider is having all the objects placed inside another container object and just maintain the index of the container instead of managing all of the individual objects.
Copy link to clipboard
Copied
EDIT: Sorry, I think I figured this out myself! Thanks anyways for the help.
"You can just use addChild() to place an object above any others."
Well, the problem is I'm adding other Children after the itemAttach Children that cover up the itemAttach Children. I was hoping to find a solution that somehow kept the itemAttach Children above everything else, rather than having to add and remove them all the time simply to keep them above everything else.
Could you maybe explain how I can use setChildIndex properly? For instance, can I set the index of a group of array-created objects?
One thing you might consider is having all the objects placed inside another container object and just maintain the index of the container instead of managing all of the individual objects.
This seems a little out of my league right now. I'll keep it in mind, though, for future projects.
Copy link to clipboard
Copied
You should share your solution for the benefit of others like yourself.
You don't remove anything, you just re-add them using addChild(). You are not adding new things you are adding things that exist already.
As far as using setChildIndex, if the goal is to place things atop everything else, using addChild() takes care of that without needing to specify where to place it. Otherwise, using setChildIndex you would specify numChildren-1 as the index for each object.
Copy link to clipboard
Copied
Sorry, basically I think for now I'm just going to set my "scenes" to an index number of 0 whenever the function runs to add them so that they're beneath everything else. I discovered that apparently I can use setChildIndex as setChildIndex (ChildName, IndexNumber), like setChildIndex(campScene, 0). (I thought it had to be more complex than that, but this actually seems sufficient.)
Just me being an noob.
Copy link to clipboard
Copied
It is a sufficient solution... either you place things on top of other things, or move the other things behind things. There's less work if there's less of them.
If you were to have placed all those ItemAttach objects inside a movieclip/sprite, then you could just keep moving that one container to the top. But what you have works.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now