-
Senior Member
Cannot removeChild
I have a movieclip created like this:
Code:
var legsArrow:MovieClip = new moreArrow();
legsArrow.x = 0;
legsArrow.y = 0;
legsArrow.name = 'legsDirection';
trace('add legsArrow: ' + legsArrow.name);
slides.addChild(legsArrow);
The remove code traces:
Code:
if(slides.getChildByName('legsDirection') != null){
trace('remove legsArrow');
slides.removeChild(slides.legsDirection);
}
I check for the existence of legsDirection movieclip, but I keep getting 2007 error about parameter child must be non-null ... but I am checking to make sure it is not null, but it passes the null test and traces fine!?
Anybody see what I'm doing wrong?
-
.
HI,
You can do it like so
PHP Code:
if (slides.getChildByName('legsDirection')) { trace('remove legsArrow'); slides.removeChild(slides.getChildByName('legsDirection')); }
-
Senior Member
Originally Posted by fruitbeard
HI,
You can do it like so
PHP Code:
if (slides.getChildByName('legsDirection')) { trace('remove legsArrow'); slides.removeChild(slides.getChildByName('legsDirection')); }
Thank you so much fruitbeard. Quick question for my sanity ...
When setting instance name for new MovieClip
Code:
legsArrow.name = 'legsDirection';
Why can't I reference it like so:
Code:
slides.legsDirection
But instead, I have to use:
Code:
slides.getChildByName('legsDirection')
I can't find anything about why I need to do this, at least in this instance. My understanding was that adding name instance property meant that I could reference my new child MovieClips like any other movieclip. Having to call getChildByName seems excessive, but perhaps I am missing something about how I am adding movieClips. AS3 really has changed since AS2.
Last edited by ::bluemoth::; 04-03-2015 at 08:14 AM.
-
.
Hi,
Because legsDirection does not exist, its just a name, so you need to reference it by name
you could also have used
PHP Code:
if (slides.getChildByName('legsDirection')) { trace('remove legsArrow'); slides.removeChild(legsArrow); }
or
PHP Code:
if (legsArrow) { trace('remove legsArrow'); slides.removeChild(slides.getChildByName('legsDirection')); }
or
PHP Code:
if (legsArrow) { trace('remove legsArrow'); slides.removeChild(legsArrow); }
-
Senior Member
Originally Posted by fruitbeard
Because legsDirection does not exist, its just a name, so you need to reference it by name
Thanks for the reply fruitbeard. So addChild in AS3 does not create an object? Hmmm, I used to be able to create objects from the library in AS2 ... is there an alternative to addChild? that would create a valid object.
-
.
Hi.
var legsArrow:MovieClip = new moreArrow(); is what is creating the object/clip, addChild is just placing it on the stage etc ect
as for an alternative I have no idea without searching
-
Senior Member
Originally Posted by fruitbeard
legsArrow:MovieClip = new moreArrow(); is what is creating the object/clip, addChild is just placing it on the stage etc
Funny that. Without being placed on the stage ... it technically doesn't exist. Yet addChild doesn't create it. Over 10 years and I still cannot understand Flash sometimes.
-
.
Hi,
I think its totally logical.
legsArrow:MovieClip = new moreArrow(); declares and creates a new movieClip called legsArrow.
legsArrow.name = 'legsDirection'; is the same as adding a value to legsArrow.
Which is similar to doing the below values.
legsArrow.value = 100;
legsArrow.number = 20;
legsArrow.name = 'legsDirection';
slides.addChild(legsArrow); adds legsArrow to the slides MovieClip.
Technically the MovieClip is called legsArrow, you are just calling the name value that you have given it, so legsDirection is not a MovieClip but only the name associated with MovieClip legsArrow.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|