• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Bring Object to Front using Actionscript

New Here ,
Jun 17, 2024 Jun 17, 2024

Copy link to clipboard

Copied

UnknownTiara_0-1718682699767.png

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.

UnknownTiara_2-1718683191869.png

UnknownTiara_1-1718683069400.png

 

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".

TOPICS
ActionScript , Code , How to

Views

169

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 18, 2024 Jun 18, 2024

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);

}

Votes

Translate

Translate
Community Beginner ,
Jun 17, 2024 Jun 17, 2024

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);
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 18, 2024 Jun 18, 2024

Copy link to clipboard

Copied

UnknownTiara_0-1718696012695.png

like this? because it didn't work for me

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 18, 2024 Jun 18, 2024

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);

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 18, 2024 Jun 18, 2024

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 18, 2024 Jun 18, 2024

Copy link to clipboard

Copied

all the burger parts are modified to movie clips! 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 18, 2024 Jun 18, 2024

Copy link to clipboard

Copied

ooh so just copy this code word for word or what do i change?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 18, 2024 Jun 18, 2024

Copy link to clipboard

Copied

can you share your code?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 18, 2024 Jun 18, 2024

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);

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 19, 2024 Jun 19, 2024

Copy link to clipboard

Copied

It worked! Thank you so much, you're seriously a life saver ❤️

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 19, 2024 Jun 19, 2024

Copy link to clipboard

Copied

LATEST

you're welcome.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 18, 2024 Jun 18, 2024

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines