Skip navigation
thunderxlight11111
Currently Being Moderated

the deffrent between children and visibles objects

Aug 14, 2012 2:09 AM

hi

i have problem here because iam confusing between these things , i know that visible property has to values true and false , and addchild is another thing because when you have two objects

then you put object 2 in object1 and i it will have its own x,y postion depend on that object , and object 1 is child for the main stage , but here is the problem

i.ve opened discuss before this

http://forums.adobe.com/message/4615780#4615780

 

and when i remove the child , its effect will be there ?? on the stage !! it is like hiding object

? so iam very confuse now , also if removechild doesn,t remove the object from existing then how can i remove it??

 

thank you and i hope you guys get what imean in my question

please check this link (my old discuss)

http://forums.adobe.com/message/4615780#4615780

 

thank you

 
Replies
  • kglad
    72,357 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 14, 2012 2:50 AM   in reply to thunderxlight11111

    if you want to destroy a display object, remove it from the display list, remove all listeners and object references and null the object.  for example,

     

    bat1.parent.removeChild(bat1);  // if bat1 is in display list

    bat1.removeEventListener(Event.ENTER_FRAME,f);  // if this listener was previously added

    batArray.splice(batArray.indexOf(bat1),1);  // if bat1 is in the array batArray

    bat1=null;

     
    |
    Mark as:
  • kglad
    72,357 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 14, 2012 3:21 AM   in reply to thunderxlight11111

    no, you didn't.  where is bat1=null??

     

    putting null; on a line by itself in your Bat1 class does nothing.

     
    |
    Mark as:
  • kglad
    72,357 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 14, 2012 3:51 AM   in reply to thunderxlight11111

    the last thing you do is null bat1:

     

     

     

    if (hero.hitTestObject(portal3)){

          var map4:BACKGROUND = new BACKGROUND();

          if(bat1){

         removeChild(bat1)

         bat1.removeEventListener(Event.ENTER_FRAME, onEnterFrame);  // this doesn't need to be done unless you added a listener outside the Bat1 classs

         bat1 = null;

     
    |
    Mark as:
  • kglad
    72,357 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 14, 2012 4:02 AM   in reply to thunderxlight11111

    that error is not from the code i suggested.  somewhere in your code you're trying to reference bat1 after it is nulled.

     

    use an if-statement to prevent that.

     

    if(bat1){

     

    }

     
    |
    Mark as:
  • kglad
    72,357 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 14, 2012 7:45 AM   in reply to thunderxlight11111

    if(bat1) means is bat1 not null.  ie, before you null bat1 the code within the if-statement (your hittest) will execute.  after you null bat1, that code will not execute and that will prevent the 2007 error.

     

    if(bat1.stage) checks if bat1 is in the display list.

     
    |
    Mark as:
  • kglad
    72,357 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 14, 2012 11:57 AM   in reply to thunderxlight11111

    you're welcome.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Incoming Links

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points