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

Detect previous child

New Here ,
Nov 23, 2013 Nov 23, 2013

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.

TOPICS
ActionScript
457
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 ,
Nov 23, 2013 Nov 23, 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;

}

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
New Here ,
Nov 23, 2013 Nov 23, 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.

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 ,
Nov 24, 2013 Nov 24, 2013
LATEST

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.

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