Skip to main content
Known Participant
November 24, 2013
Question

Detect previous child

  • November 24, 2013
  • 1 reply
  • 480 views

I create 3 childs in my actionscripts. If I click "A", it will addChild "C", If I click "B", it will also addChild "C". A and B buttons are not in the same page. Now I want to go back to A and B after addChild C depends on previous child.

If I click A, then C, Back to A

If I click B, then C, Back to B

It is just similar to go back button. How can I do?

mainPage.btn1.addEventListener(MouseEvent.CLICK, onGoCon);

page1.btn2.addEventListener(MouseEvent.CLICK, onGoCon);

funtion onGoCon (evt:MouseEvent):void{

if (currentPage!=null){

removeChild(currentPage);}

addChild(C);

currentPage=C;

}

Now I want to go back. If I am from mainPage.Then go to mainPage. If I am from page1. then go to page1.

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
November 24, 2013

There are a number of ways you could deal with this. One would be to assign the object that opened C to C as a property.  You could then target that object thru C.

funtion onGoCon (evt:MouseEvent):void{

   if (currentPage!=null){

      removeChild(currentPage);

   }

  C.opener = Object(evt.currentTarget);

  addChild(C);

  currentPage=C;

}

Known Participant
November 24, 2013

mainPage.btn1.addEventListener(MouseEvent.CLICK, onGoCon);

page1.btn2.addEventListener(MouseEvent.CLICK, onGoCon);

funtion onGoCon (evt:MouseEvent):void{

if (currentPage!=null){

removeChild(currentPage);}

addChild(C);

currentPage=C;

}

Now I want to go back. If I am from mainPage.Then go to mainPage. If I am from page1. then go to page1. There is a back button for me to go back.  Is C.opener = Object(evt.currentTarget);  the Object the back button? But I do not use the back button to be an opener.

Ned Murphy
Legend
November 24, 2013

I don't bother trying to hit moving targets, so you will have to make up your mind what you want to click.  You said....

If I click A, then C, Back to A

If I click B, then C, Back to B

My response would not change in its concept except you will have to decide what you store in C that you want to use to decide what to go back to.  Whatever this new back button does it can call upon whatever you assign to C for that purpose.  So instead of ...

    C.opener = Object(evt.currentTarget);

you could use something like

    C.opener = "mainPage"

or whatever else you decide to change it to.  The back button will just utilize C.opener to make its decision.

You would not even have to store it in C.  You could store it as a general variable as well.