简体   繁体   English

ActionScript Flash游戏需要将加载程序类对象传递给外部SWF

[英]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. Flash游戏中,容器swf使用加载程序类加载img。

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. 我遇到的问题是,我原来每个级别都加载了地图图像,转换为位图,然后使用它来创建x和y来进行大肠菌病检测。

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. 还需要注意的是,每个级别都在加载相同的图像,如果以上情况发生在第3,第4级别,则非常烦人。

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: 家长SWF:

(This code is in the constructor) (此代码在构造函数中)

var mImageLoader = 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 然后将子SWF加载到构造函数之外

CHILD SWF: 儿童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 确实需要在子对象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. 如果父SWF引用了已加载的子SWF,则可以只设置子SWF的属性或调用子SWF的方法来传递位图。 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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM