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

Make Back button in Movie Clip ?

Guest
Dec 19, 2013 Dec 19, 2013

Im tryign to make a back button in my  program but it is not working

here is my code

I have to buttons on my movie clip called jupiterback and bb which are instances

Header 1

  public class Main extends MovieClip

    {

     

        var hp:HomePage;

        var sp:StartPage;

        var sunP:SunPage ;

        var jupiterP:JupiterPage;

        var vx:Number;

        var vy:Number;

        var speed:int;

        var score:Number;

        var aship:Ship = new Ship();

        var s1:Sun = new Sun();

        var j1:Jupiter = new Jupiter ();

        public function Main()

        {

             sp = new StartPage();

             hp = new HomePage();

             sunP = new SunPage();

             jupiterP = new JupiterPage();

            vx = 0;

            vy = 0;

            score = 0;

           

           

            addEventListener(KeyboardEvent.KEY_UP, onKeyUp);

            addEventListener(Event.ENTER_FRAME, onEnterFrameSun);

            addEventListener(Event.ENTER_FRAME, onEnterFrameJupiter);

      

            // Start Page Event Listener

            sp.sb.addEventListener(MouseEvent.CLICK, onStartButtonClick);

            addEventListener(MouseEvent.CLICK, onStartButtonClick);

            stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHit);

            addChild (sp); 

           

         

            jupiterP.bb.addEventListener(MouseEvent.CLICK, onBackButtonClickJupiter);

           

            jupiterP.jupiterback.addEventListener(MouseEvent.CLICK, onBackButtonClickJupiter);

            addEventListener(MouseEvent.CLICK, onBackButtonClickJupiter);

        }

       

      

       

        function onBackButtonClickJupiter(event:MouseEvent):void

        {

           

            if (jupiterP != null && contains(jupiterP)) {

                removeChild(this.sp.homePage.jupiterP);

                addChild(hp);

            }

// Ive tried this method too but doesnt work

function onBackButtonClick_Jupiter(event:MouseEvent):void

        {

            addChild(hp);

            removeChild(jupiterP);

        }

TOPICS
ActionScript
842
Translate
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
Guest
Dec 19, 2013 Dec 19, 2013

These are the errors it gives me

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.

    at flash.display::DisplayObjectContainer/removeChild()

    at Main/onEnterFrameJupiter()[Desktop\Main.as:229]

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.

Translate
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 ,
Dec 19, 2013 Dec 19, 2013

I don't see where you ever addjupiterP as a child.  If you don't add it, it cannot be removed.

Translate
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
Guest
Dec 19, 2013 Dec 19, 2013

i have a start page that has jupiterP inside it its called hp

when i click my startbutton hp opens up. I have a ship the ship moves to the planet jupiter and upon hitTest jupiterP opens up now i want to get back to hp using a button

function onStartButtonClick(event:MouseEvent): void

        {

           

            if (contains (sp))

               

            {

            removeChild(sp);

            addChild(hp);

           

            }

Translate
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 ,
Dec 19, 2013 Dec 19, 2013

The jupiterP you test for in the code below is not the same jupiterP that lives somewhere inside sp

            if (jupiterP != null && contains(jupiterP)) {

                removeChild(this.sp.homePage.jupiterP);

                addChild(hp);

            }

Translate
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
Guest
Dec 19, 2013 Dec 19, 2013

What do I have to enter to find the instance of jupiterP inside sp ?

Translate
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
Guest
Dec 19, 2013 Dec 19, 2013

If i can do this I will be done does someone know how I can find that Instance ?

Translate
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
Guest
Dec 19, 2013 Dec 19, 2013

hello Mr Ned Murphy

Translate
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 ,
Dec 19, 2013 Dec 19, 2013

Here's what I'd try based on what you showed...

if (sp.homePage.jupiterP != null && sp.homePage.contains(jupiterP)) {

                sp.homePage.removeChild(sp.homePage.jupiterP);

                addChild(hp);

}

and if you do not have an jupiterP instance being created for anything in that class, get rid of it from what you show in the class.

One other way to approach this might be to just make it invisible.  That way you don't have to wonder so much about properly targeting it.  It could reduce that entire conditional down to...

sp.homePage.jupiterP.visible = false;

addChild(hp);

Regarding your persistent follow-ups... I'm not complaining and am not trying to come off as angry... just realize I do not live in these forums, so you have to learn to be patient.

Translate
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
Guest
Dec 19, 2013 Dec 19, 2013
LATEST

Sorry about the persistence i was desperate. Anyway i still couldnt get it to work so i took my game in a diffrent direction. Thanks

Translate
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