开发者

can't trace the child of a sprite

Maybe there's something I don't understand about the qualities of a sprite, but why does this trace as undefined? item is a movie clip and businessCard is a sprite which contains a movie clip.

item.addChild (businessCard);/开发者_开发技巧/
trace (item.businessCard);//


MovieClips are dynamic, so you can create and access properties with dot notation. Sprites are not dynamic. To get a reference to a child, you have to access the item like this:

trace(item.getChildByName("businessCard").name)//traces => businessCard

[EDIT] I assumed that the sprite businessCard's name is "businessCard".


businessCard is a child of item, not a property. You can't access it with dot notation like that. You'll have to use something like item.getChildAt(0);


I would make a class like this:

package 
{
    import flash.display.Sprite;

    public dynamic class FlexSprite extends Sprite
    {
        public function FlexSprite()
        {
        }
    }
}

And than in your code:

var item:FlexSprite = new FlexSprite();

//Extra Code
trace(item.bussinesCard);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜