开发者

actionscript flash game need to pass loader class object to external swf

I am really pulling my hair out with this one. Flash game, container swf loads a img using the loader class.

The image is the map which will be used on the levels.

The problem im having is that I originaly had each level load the map image, convert to a bitmap, and us it to create x and y's for colision detection.

the problem was that the game was loading and sometimes the map image hadent loaded. It also ment that each level was loading the same image and if the above happened on the 3rd, 4th level it was very annoying.

So I need a way to load the image in the parent, but have it available to the child, however it must be available as at bitmap to work.

Here is the code I have

PARENT SWF:

(This code is in the constructor)

var mImageLo开发者_开发问答ader = new Loader();
var anImageURLRequest:URLRequest = new URLRequest('http://example.com/Level-map.png');
mImageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
mImageLoader.load(anImageURLRequest);

The child SWF is then loaded outside of the constructor

CHILD SWF:

map1 = Bitmap(mImageLoader.content);
        bmd1 = map1.bitmapData;

        addChild(map1);

Obviusly the above doesnt work, but is ideally how I need it to work Anyone got any Ideas?

Really need to access the loader object after its loaded the image frmo the child swf

Thanks

Andrew


If parent SWF has a reference to the loaded child SWF, you can just set a property of the child or call a child's method to pass the bitmap. Here's what I'm talking about:

// Child.as
public function setBitmap(value:Bitmap):void
{
    addChild(value);
}

// Parent.as
public function Parent()
{
    // load child
    var loader:Loader = new Loader();
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadedChild);
    loader.load('Child.swf');
}

private function loadedChild(event:Event):void
{
    var loaderInfo:LoaderInfo = event.currentTarget as LoaderInfo;
    loaderInfo.removeEventListener(Event.COMPLETE, loadedChild);

    // 'bitmap' contains the reference to your Bitmap
    var child:Child = loaderInfo.content as Child;
    child.setBitmap(bitmap);
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜