开发者

AS3 LoaderMax: Loading pictures to an array?

开发者 https://www.devze.com 2023-04-11 08:47 出处:网络
I have the following problem. I wanna load 3 pictures to the stage using LoaderMax. Their path is stored in an array (urls), and finally I wanna have all their displayList objects in a new array calle

I have the following problem. I wanna load 3 pictures to the stage using LoaderMax. Their path is stored in an array (urls), and finally I wanna have all their displayList objects in a new array called pictures.

here's my code:

 var urls:Array = new Array("../data/bild1.jpg","../d开发者_如何学Pythonata/bild2.jpg", "../data/bild3.jpg");
     for(var i:Number = 0; i< urls.length; i++){
       var loadery = new ImageLoader(urls[i]);
       loadery.load()
       pictures[i] = loadery;
       addChild(pictures[i]);
       pictures[i].alpha = .5;

I want them to be stored in the array "pictures", because I wanna do later several things with them, which are more simple, if they are stored in an array.

So, Flash gets an compiler error for pictures[i] = loadery; It says TypeError: Error #1009: Cannot access a property or method of a null object reference.

So how can I do this easily?

Thank you for your help.


ImageLoader doesn't load content synchronuosly, to get loaded image instance you have to listen to onImageLoad event:

function onImageLoad(event:LoaderEvent):void {
    // you image is accesible from event.target.content variable
}

To load several images you can use LoaderMax object which will queue your loadings, to see exactly how use ImageLoader class read it's documentation

0

精彩评论

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

关注公众号