开发者

AS3 + addChild() getting image from library to the stage

开发者 https://www.devze.com 2022-12-19 23:47 出处:网络
I have an .fla file with 1 image in the library and 1 .as file. I have linked the image up with the Class name of libraryI开发者_运维技巧mages and Base class is flash.display.BitmapData.

I have an .fla file with 1 image in the library and 1 .as file.

I have linked the image up with the Class name of libraryI开发者_运维技巧mages and Base class is flash.display.BitmapData.

This is my AS:

package {
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.MovieClip;

    public class Banner extends MovieClip { 
        var defaultImage:libraryImages = new libraryImages(469, 60);
        var myImage:Bitmap = new Bitmap(defaultImage);
        addChild(myImage);
    }
}

I am getting two errors:

1180: Call to a possibly undefined method addChild.
1120: Access of undefined property myImage.

Any ideas?


You forgot the constructor, oops.

It has to be

package {
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.MovieClip;

    public class Banner extends MovieClip { 

        public function Banner()
        {
            var defaultImage:libraryImages = new libraryImages(469, 60);
            var myImage:Bitmap = new Bitmap(defaultImage);
            addChild(myImage);
        }
    }
}
0

精彩评论

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

关注公众号