-
1. Re: adding and removing child
_spoboyle Apr 19, 2012 8:44 AM (in response to thunderxlight11111)in the first example you gave
when you construct MAINMAP1 it tries to add itself to its parent.
but it's doesn't have a parent yet cause you haven't added it to anything
in the second example you manually add MAINMAP1 to the stage (it now has a parent)
so when you construct MAINMAP it removes itself from its parent
to be honest I am suprised even the second one worked
-
2. Re: adding and removing child
thunderxlight11111 Apr 19, 2012 9:20 AM (in response to _spoboyle)ohh thank you
can you please tell me how can i add parent to this class from the begin (i want the main stage to be its parent) or can you fix it please if you dont mind
thank you
-
3. Re: adding and removing child
_spoboyle Apr 20, 2012 1:15 AM (in response to thunderxlight11111)1 person found this helpfuleither add MAINMAP1 using addChild in the constructor of your document class (if you have one)
or you'll have to add it on the time line
you should add an eventlistener in the constructor of MAINMAP
addEventListener(Event.ADDED_TO_STAGE, onAdded);
and then in your function onAdded you can access parent
-
4. Re: adding and removing child
thunderxlight11111 Apr 20, 2012 3:35 AM (in response to _spoboyle)thanks
the first way i did it in the first game but here i wanna make game with only 1 class , i will link it later
the second i did it in the same class like this
package
{
import flash.system.System;
import flash.system.fscommand;
import flash.display.MovieClip;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.Stage;
public class MAINMAP1 extends MovieClip {
public function MAINMAP1(){
addEventListener(Event.ADDED_TO_STAGE, onAdded)
}
public function onAdded (event:Event):void {
MovieClip(parent).addChild(this);
}
}
}
the problem still
maybe i forget something?
thank you
-
5. Re: adding and removing child
_spoboyle Apr 20, 2012 3:50 AM (in response to thunderxlight11111)1 person found this helpfulonAdded get's called after addChild so what you have written makes no sense.
if MAINMAP is you document class then you don't need to call addChild that will happen automatically
-
6. Re: adding and removing child
thunderxlight11111 Apr 20, 2012 3:59 AM (in response to _spoboyle)yeah i know that brother
but i want it to be in the same class inside because i have lvl 1 and 2 and 3
can you please fix that code to make the main its parent
thank you alot brother For your patience
-
7. Re: adding and removing child
_spoboyle Apr 20, 2012 4:57 AM (in response to thunderxlight11111)1 person found this helpfulSorry I don't understand what you are after
-
8. Re: adding and removing child
thunderxlight11111 Apr 20, 2012 4:59 AM (in response to _spoboyle)which thing you dont get it?
-
9. Re: adding and removing child
_spoboyle Apr 20, 2012 5:00 AM (in response to thunderxlight11111)1 person found this helpfulwhat you are trying to achieve
-
10. Re: adding and removing child
thunderxlight11111 Apr 20, 2012 5:03 AM (in response to _spoboyle)i just want to add some code to this code to let it work from MAINMAP class
package
{
import flash.system.System;
import flash.system.fscommand;
import flash.display.MovieClip;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.Stage;
public class MAINMAP1 extends MovieClip {
public function MAINMAP1(){
MovieClip(parent).addChild(this);
}
}
}
can you please do that?
some codes to let it work well in this code
-
11. Re: adding and removing child
_spoboyle Apr 20, 2012 5:42 AM (in response to thunderxlight11111)you can't
you can never call MovieCli(parent).addChild(this) / as I am sure you understand now you don't have access to parent until after calling addChild()
ok let's try and take this step by step
do you have a document class? if so please paste it here
-
12. Re: adding and removing child
thunderxlight11111 Apr 20, 2012 5:44 AM (in response to _spoboyle)no i dont have only 1 class in the library
-
13. Re: adding and removing child
_spoboyle Apr 20, 2012 5:45 AM (in response to thunderxlight11111)so you are adding you actionscript on the timeline?
-
14. Re: adding and removing child
thunderxlight11111 Apr 20, 2012 5:50 AM (in response to _spoboyle)no its out in the folder
-
15. Re: adding and removing child
_spoboyle Apr 20, 2012 5:58 AM (in response to thunderxlight11111)Yes MAINMAP1 might be an external class, but you need to to either have a document class or add code the timeline as well
-
16. Re: adding and removing child
thunderxlight11111 Apr 20, 2012 6:20 AM (in response to _spoboyle)ohh so there is no solutin except this right?
-
17. Re: adding and removing child
_spoboyle Apr 20, 2012 6:22 AM (in response to thunderxlight11111)a class can't add itself to the display list. you have access to the display list from a document class or the timeline. you can then add any other objects to the display list including your MAINMAP1
-
18. Re: adding and removing child
thunderxlight11111 Apr 20, 2012 6:30 AM (in response to _spoboyle)oh thank you alot brother , i get it now all