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

How to remove a child from view in actionscript 3.0?

Community Beginner ,
Jun 21, 2013 Jun 21, 2013

I am working with a movieclip labeled tut_mc and inside it i have a button named tut_x_btn. what i want to happen when the X button clicked is to remove the tut_mc from the main timeline. I do not know much about the child commands in Flash. i know that i will have to access the maintimeline with MovieClip(root) command to remove the movieclip. and also how would you do the opposite when a button in clicked adding a child that exists in the library?

TOPICS
ActionScript
1.3K
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

correct answers 1 Correct answer

LEGEND , Jun 21, 2013 Jun 21, 2013

One more proper way to attack this is to have the code for the button in the main timeline, targeting it thru the movieclip...

tut_mc.tut_x_btn.addEventListener(MouseEvent.CLICK, removeTut);

function removeTut(evt:MouseEvent):void {

      removeChild(tut_mc);

}

I would do the same approach for adding a child from the library.

That approach avoids doing what you suggested doing which is not really proper oop implementation.... child objects should not direct the activities of their parent objects -  th

...
Translate
LEGEND ,
Jun 21, 2013 Jun 21, 2013

One more proper way to attack this is to have the code for the button in the main timeline, targeting it thru the movieclip...

tut_mc.tut_x_btn.addEventListener(MouseEvent.CLICK, removeTut);

function removeTut(evt:MouseEvent):void {

      removeChild(tut_mc);

}

I would do the same approach for adding a child from the library.

That approach avoids doing what you suggested doing which is not really proper oop implementation.... child objects should not direct the activities of their parent objects -  they should not have to rely on their existence, which target the parent/root does.

If you wanted to go the way you suggested, you could use MovieClip(root).removeChild(tut_mc);  (I'm not sure if you also need to target MovieClip(root).tut_mc for the argument though... been awhile.)  But using root references can be chancy when you start involving separate files.  Sometimes it is better to use parent targets instead.

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
Community Beginner ,
Jun 21, 2013 Jun 21, 2013

i tried the code in multiple locations, but it is giving me an error when i go to test it its saying access of unidentified property tut_mc when i try to restructure its suggesting i should use MovieClip(root).removeChild(child:DisplayObject):DisplayObject

i am not sure what it is suggesting. i am sure its asking me to fill in the proper areas with the tut_mc but i am not sure about that.

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
Advocate ,
Jun 22, 2013 Jun 22, 2013

tut_mc.tut_x_btn.addEventListener(MouseEvent.CLICK, removeTut);

function removeTut(evt:MouseEvent):void {

      tut_mc.tut_x_btn.removeEventListener(MouseEvent.CLICK, removeTut);

      MovieClip(tut_mc.parent).removeChild(tut_mc);

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 ,
Jun 22, 2013 Jun 22, 2013
LATEST

There is only one location for the code I showed, the timeline that contains tut_mc.

If the program is suggesting you use MovieClip(root), that's a sad reflection of whoever is coding this software.

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