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

Button to remove movieclip and jump to new scene error

Explorer ,
Jan 22, 2022 Jan 22, 2022

Copy link to clipboard

Copied

I am not a developer so pardon the dumb question.

 

I have 2 scenes.  (really many more than 2, but for this question we will say 2 scenes).

 

Scene 1 links to Scene 2.


In my scene 2 I have a scrollpane with two buttons.  Each button links to a frame in the timeline.  That's working great after I found some answers on this board.  Here is the scrollpane code:

 

import fl.containers.ScrollPane;
import fl.controls.ScrollPolicy;
import fl.controls.DataGrid;
import fl.data.DataProvider;

var aSp:ScrollPane = new ScrollPane();
var aBox:MovieClip = new MovieClip();

aSp.source = member_snapshot_tiles;
aSp.setSize(1340, 170);
aSp.move(570, 110);

addChild(aSp);


Now I need to have a button that goes back to Scene 1.  The button works but the scrollpane from Scene 2 appears in Scene 1.

I found this snippet on the board:

btnHeim.addEventListener(MouseEvent.CLICK,heimClick);

function heimClick(e:MouseEvent):void {

    loader.unload();

    gotoAndStop(1,"Mainpage");

}


and modified it:

 

button_54.addEventListener(MouseEvent.CLICK,heimClick);

function heimClick(e:MouseEvent):void {

member_snapshot_tiles.removeChild(ScrollPane);

MovieClip(this.root).gotoAndPlay(1, "vistaroster");

}

 

Unfortunately I am not a developer so I can't seem to find the right combo of labels to make this work.  How can I add a button that removes the scrollpane and returns the user to Scene 1?

Views

110

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
Explorer ,
Jan 22, 2022 Jan 22, 2022

Copy link to clipboard

Copied

Update...I seem to have stumbled on to the right combination.  LOL, I'm such a hack noob.  Everyone take the time to ridicule me.  It's good for my ego.

button_54.addEventListener(MouseEvent.CLICK,heimClick);

function heimClick(e:MouseEvent):void {

if ( null != aSp.stage )

{
removeChild( aSp );
}




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
LEGEND ,
Jan 22, 2022 Jan 22, 2022

Copy link to clipboard

Copied

What you wrote about aSp.stage is similar to my test for its parent, and you figured out the main issue. Setting it to null is still worth doing.

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
LEGEND ,
Jan 22, 2022 Jan 22, 2022

Copy link to clipboard

Copied

You have referred to the ScrollPane as aSp, but you are doing a removeChild(ScrollPane). If you are sure of what aSp's parent is (like it looks as if it is member_snapshot_tiles) you can do the remove that way. If there is a chance you're at a different point in the hierarchy you could test to see if aSp has a parent, then remove it, or you could addChild(aSp), then remove it. In both cases setting the variable to null would be worth it, to free up memory.

So, either of these might work:

if(aSp.parent){
aSp.parent.removeChild(aSp);
aSp = null;
}

or:

addChild(aSp);
removeChild(aSp);
aSp = null;

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
Explorer ,
Jan 22, 2022 Jan 22, 2022

Copy link to clipboard

Copied

LATEST

Thank you for the feedback.  I am 100% your solution is more elegant.  I will take a look at replacing my hack code with yours when I am finished creating my other screens.

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