Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 07-08-2009, 07:12 AM   #1
atksheu
Registered User
 
Join Date: Jul 2009
Posts: 17
Default Flash cant find child to remove even though it is clearly there.

Hi,

I am working on a website right now, which involves using framescripts to invoke instance methods from the document class. These methods are supposed to trigger the new content of each page, e.g. a galleryCreate() method that creates an instance of a custom Gallery class. The other job that this method must perform is run a check to see if there are any other children that need to be removed prior to trying to bring up the new content (for example, to prevent multiple Gallery instances from being created, or a Gallery instance being created when a Newsfeed instance is still on the display list).

This was the solution I tried:

script on frame labeled "gallery":

ActionScript Code:
galleryCreate();


script in document Class after the main constructor. Spaceball is an empty MovieClip declared at the beginning of the class as an easy point of reference to the root.

ActionScript Code:
public function galleryCreate () {     if ((spaceball.parent.getChildByName("gallery")) != null) {         trace("An instance of the Gallery object was found and deleted");         removeChild(spaceball.parent.getChildByName("gallery"));     }             gallery = new Gallery();     addChild(gallery); }


When I ran the program, I clicked on the button to the gallery page, and the gallery came up alright. However, when I clicked on it a second time, I could see from the alpha of some of the elements that additional classes were being placed on top of the original ones. The trace in the if statement was never registered.

So to troubleshoot this problem, I inserted the first two traces into the beginning of the galleryCreate() method, and the last trace at the end.

ActionScript Code:
trace(spaceball.parent) //returns [Object Body], Body being the document class     trace(spaceball.parent.getChildByName("gallery"))//returns null     //after Gallery has been instantiated in the new gallery object     trace(gallery.parent);    //this returned [Object Body]


Running the program again, the trace(spaceball.parent.getChildByName("gallery") would consistently return null, followed right after by a trace that recognizes the parent of the newly instantiated Gallery object to be the Document class. Doesn't that mean that it should be recognized as a child during the second iteration of galleryCreate()? Me = very confused.

Any help would be greatly appreciated. Also, if you have any observations about whether this is a good approach at all, please let me know. I am new to using Flash as a web design tool and I am still unsure how to think about designing the architecture of a web site. Thank you very much!
atksheu is offline   Reply With Quote
Old 07-08-2009, 07:25 AM   #2
tadster
tadster
 
tadster's Avatar
 
Join Date: Feb 2009
Location: Texas
Posts: 2,111
Default

what child has the name gallery? i don't see that in the code you gave,
if your trying to reference the gallery frame, you can't do it that way.

Code:
gallery = new Gallery();
    addChild(gallery);
the above code creates a gallery object.
only display objects can have names, if your Gallery Class does not extend a display object (sprite, movieclip...) it does not get a name, even so you would first have to give it "gallery" as its name : gallery.name = "gallery";
tadster is offline   Reply With Quote
Old 07-08-2009, 07:32 AM   #3
abeall
Senior Member
 
Join Date: Feb 2006
Location: Washington, DC
Posts: 2,796
Send a message via AIM to abeall
Default

getChildByName will search for a child display object which has the name property set to the value specified, it does not search the properties on the display object and match up a reference name. In other words, you need to give the display object a name or else it has no name so getChildByName will not find it. Assign it to the property "gallery" is not the same as giving it a name. So either give it a name:

ActionScript Code:
gallery = new Gallery(); gallery.name = "gallery"; addChild(gallery);

Or probably just as well to adjust your conditional to check the property itself:

ActionScript Code:
if (gallery != null) {
__________________
Aaron Beall | Flash portfolio | Fireworks extensions | Twitter
abeall is offline   Reply With Quote
Old 07-08-2009, 07:44 AM   #4
atksheu
Registered User
 
Join Date: Jul 2009
Posts: 17
Default

Ah i see. I guess I thought that instantiating the object also assigned that variable as its name in the display list. Thanks a lot! That fixes the problem,
atksheu is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:25 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.