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

the deffrent between children and visibles objects

Participant ,
Aug 14, 2012 Aug 14, 2012

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

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

Community Expert , Aug 14, 2012 Aug 14, 2012

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){

}

Translate
Community Expert ,
Aug 14, 2012 Aug 14, 2012

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;

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
Participant ,
Aug 14, 2012 Aug 14, 2012

thx , i did all these steps but in the bat still exist

look

1- remove it from display list

in the main class

if (hero.hitTestObject(portal3)){

      var map4:BACKGROUND = new BACKGROUND

      if(bat1.stage){

     removeChild(bat1)

     bat1.removeEventListener(Event.ENTER_FRAME, onEnterFrame);

     }

2-remove it from the display list, remove all listeners and object references and null the object.

in the bat1 class

private function onRemovedFromStage(event:Event):void

  {

   removeEventListener(Event.ENTER_FRAME, onEnterFrame);

   removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);

   removeEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);

   null;

  

   trace("bat removed");

  }

thank you

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 Expert ,
Aug 14, 2012 Aug 14, 2012

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

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

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
Participant ,
Aug 14, 2012 Aug 14, 2012

here

if (hero.hitTestObject(portal3)){

      var map4:BACKGROUND = new BACKGROUND

      if(bat1.stage){

     removeChild(bat1)

     bat1 = null;

     bat1.removeEventListener(Event.ENTER_FRAME, onEnterFrame);

but i get these thing after getting to the portal

TypeError: Error #2007: Parameter hitTestObject must be non-null.

at flash.display::DisplayObject/_hitTest()

at flash.display::DisplayObject/hitTestObject()

at MAIN/onEnterFrame()

thank you for your replay

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 Expert ,
Aug 14, 2012 Aug 14, 2012

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;

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
Participant ,
Aug 14, 2012 Aug 14, 2012

i copied it then i paste in my code but the errors still!

thank you again for your replay

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 Expert ,
Aug 14, 2012 Aug 14, 2012

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){

}

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
Participant ,
Aug 14, 2012 Aug 14, 2012

maybe , am gonna delete all the classes and doing all the game in the main because i get enough of errors

thank you alot kgald  but is if(bat1) mean that bat 1 on the stage  and if it is yes , what the deffrent between it andif(bat1.stage) because they look the same they both have to values true and false

thx again

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 Expert ,
Aug 14, 2012 Aug 14, 2012

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.

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
Participant ,
Aug 14, 2012 Aug 14, 2012

thanks alot kgald

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 Expert ,
Aug 14, 2012 Aug 14, 2012
LATEST

you're welcome.

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