# Casting woes

**URL:** <https://forum.kirupa.com/t/casting-woes/264377>\
**Category:** Uncategorized\
**Created:** [June 25, 2008, 3:59pm UTC](https://forum.kirupa.com/t/casting-woes/264377 "2008-06-25T15:59:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [June 25, 2008, 3:59pm UTC](https://forum.kirupa.com/t/casting-woes/264377/1 "2008-06-25T15:59:43Z")

</div>

Imagine a quick scenario;

\_thumbs is a Sprite, inside it is a custom class called “thumb1” (extends MovieClip) and inside that is a sprite called “nail”. Nail is a libraryitem. Nail has a child called blocker (that’s in the library item already).

Now, this works fine;

```auto

var t = _thumbs.getChildByName("thumb"+i);
var sx = t.getChildByName("nail");
TweenMax.to(sx.blocker,1,{yada});

```

Wheras this works fine, I can’t for my life figure out how to cast these variables. If I try making them DisplayObjects or Sprites or MovieClips or whatnot it all throws error with either implicit coercion or reference to a undefined method getChildByName

Grateful for any insight.

---

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [June 25, 2008, 4:13pm UTC](https://forum.kirupa.com/t/casting-woes/264377/2 "2008-06-25T16:13:27Z")

</div>

Just to clarify, this also works fine;

```auto

var t:MovieClip;
var sx:Sprite;
// for loop stuff//
t = _thumbs.getChildByName("thumb"+i) as MovieClip;
sx = t.getChildByName("nail") as Sprite;
TweenMax.to(sx.getChildByName("block");
// end loop stuff//

```

but it feels really clunky. What am I overlooking? 😕

---

<div class="post-metadata">

**Author:** ![Iamthejuggler](https://avatars.discourse-cdn.com/v4/letter/i/ecc23a/32.png) [@Iamthejuggler](https://forum.kirupa.com/u/Iamthejuggler)\
**Post date:** [June 25, 2008, 6:15pm UTC](https://forum.kirupa.com/t/casting-woes/264377/3 "2008-06-25T18:15:03Z")

</div>

This should work. Also a little clunky but i think you pretty much need to do it every time you use getChildByName.

var t = MovieClip(\_thumbs.getChildByName(“thumb”+i));  
var sx = Sprite(t.getChildByName(“nail”));  
TweenMax.to(sx.blocker,1,{yada});
