Copy link to clipboard
Copied
So I'm making a Burger Builder game, where the user can build their own burger by dragging and dropping the burger parts, essentially stacking them. However, I have a problem with the layers because if the user wants to have the patty as the first layer in the stack, and they want lettuce as the second layer, but then the lettuce is stacked behind the patty (if you get what I mean).
When I use the "Bring Object to Front" code snippet, when I go to the next scene, it looks like this, like the objects I clicked are showing up in the next scene, and layers that are hidden shows up.
Is there a way to fix this? Because the code snippet makes it that everything in the scene is clickable, so how do I make it that only certain objects (the burger parts) are clickable to bring to the front and leave everyting else be?
I'm very new to this, so if you can, I'd like to be explained like a 5 years old "monkey see monkey do".
did you call move_to_top()?
eg, using bun click
bun.addEventListener(MouseEvent.CLICK,, onBunClick);
function onBunClick(e:MouseEvent):void{
move_to_top(MovieClip(e.currentTarget));
}
function move_to_top(mc:MovieClip):void{
mc.parent.addChild(mc);
}
Copy link to clipboard
Copied
you can use setChildIndex to set the depths of the movieclips
function onLettuceClick(event:MouseEvent):void {
// Bring the lettuce the front
setChildIndex(lettuce , numChildren - 1);
}
Copy link to clipboard
Copied
like this? because it didn't work for me
Copy link to clipboard
Copied
nurba's code is incorrect. and it's easier to use addChild:
function move_to_top(mc:MovieClip):void{
mc.parent.addChild(mc);
}
Copy link to clipboard
Copied
we did not see the whole code, maybe UnknownTiara is using already added movieclips?
if movieclips already there, then setChildIndex should work fine,
on your code addChild adds movieclips, new movieclip automatically will be at the top
Copy link to clipboard
Copied
all the burger parts are modified to movie clips!
Copy link to clipboard
Copied
ooh so just copy this code word for word or what do i change?
Copy link to clipboard
Copied
can you share your code?
Copy link to clipboard
Copied
did you call move_to_top()?
eg, using bun click
bun.addEventListener(MouseEvent.CLICK,, onBunClick);
function onBunClick(e:MouseEvent):void{
move_to_top(MovieClip(e.currentTarget));
}
function move_to_top(mc:MovieClip):void{
mc.parent.addChild(mc);
}
Copy link to clipboard
Copied
It worked! Thank you so much, you're seriously a life saver ❤️
Copy link to clipboard
Copied
you're welcome.
Copy link to clipboard
Copied
Hi.
Are the burger parts inside of the same parent? And are there any other instances in this same parent?
I think the codes suggested here work but you need to make sure youl're adding the click listener to the correct container or children and that these parts live in the same parent so that they don't go beyond the UI for example or don't appear in another screen of your game.
Regards,
JC