attachMovie()无效

时间:2012-10-02 14:14:54

标签: flash actionscript-2

这是我的代码:

var people:Array = [
    {
        image: "1.jpg",
        labels: 
            [
                "Valium dependant",
                "Anger issues",
                "Single parent"
            ]
    },{
        image: "2.jpg",
        labels: 
            [
                "Alcoholic",
                "Bipolar disorder",
                "Smokes cannabis"
            ]
    },{
        image: "3.jpg",
        labels: 
            [
                "Glue sniffer",
                "Suffers from anxiety",
                "Has terminal cancer"
            ]       
    },{
        image: "4.jpg",
        labels: 
            [
                "Ecstasy user",
                "Binge drinker",
                "Depressed"
            ]       
    },{
        image: "5.jpg",
        labels: 
            [
                "Homeless",
                "Heroin user",
                "Smokes"
            ]       
    },{
        image: "6.jpg",
        labels: 
            [
                "Uses poppers",
                "LSD user",
                "Cocaine user"
            ]       
    }
];

var thumb_container:MovieClip = this.thumb_container;
for (index in people) {
    var thumb:MovieClip = thumb_container.attachMovie("Thumbnail", "thumb_" + index, thumb_container.getNextHighestDepth());
    var image_container:MovieClip = thumb.image_container;
    var image:MovieClip = image_container.attachMovie(people[index].image, "image_" + index, image_container.getNextHighestDepth());
    trace(image);
}

问题是trace(image)返回_level0.thumb_container.thumb_0.image_container,它是image的父级。我无法弄清楚为什么它没有返回我附加的图像(图像也没有出现在SWF中)。

注意:image数组中的people属性是为ActionScript导出的链接ID。

修改:如果我将它们放入MovieClip并加载它们就可以正常工作,但似乎有很多人使用attachMovie()图片

1 个答案:

答案 0 :(得分:0)

您无法使用MovieClip.attachMovie加载位图,因为它无法识别位图文件。它的目的是仅加载动画片段而不是其他类型。因此,您必须先制作位图数据,然后将此位图数据附加到动画片段。

var thumb_container:MovieClip = this.thumb_container;
for (index in people) {
    var thumb:MovieClip = thumb_container.attachMovie("Thumbnail", "thumb_" + index, thumb_container.getNextHighestDepth());
    var image_container:MovieClip = thumb.image_container;
    var bmp:BitmapData = BitmapData.loadBitmap(people[index].image);
    var image:MovieClip = image_container.attachBitmap(bmp, image_container.getNextHighestDepth());
    trace(image);
}

它返回image并显示它。