从AS2到AS3加载外部图像
我正在将一些 Actionscript 代码从 AS2 转换为 AS3,最终我成功地让其中大部分代码再次工作(它几乎是一种完全不同的语言,只是有一点语法相似性)。 最后仍然不起作用的事情之一是加载外部图像的代码。
也许这在 AS3 中已经改变了,但我真的认为使用 loadVideo
加载图像很奇怪,为什么不使用 loadImage? (另一方面,Flash 应用程序经常被称为 Flash 视频,即使它根本不用于动画)。 这不再起作用了,我发现的是一个相当复杂的代码,据说可以替换这个 oneliner imageholder.loadVideo(url);
是这样的:
var urlreq:URLRequest = new URLRequest(url);
var theloader:Loader = new URLLoader();
theloader.load(urlreq);
theloader.addEventListener(Event.COMPLETE, function(event:Event):void {
imageholder.addChild(theloader);
}
);
但这不起作用..我做错了什么,有没有更适合在 AS3 中加载图像的函数?
I'm converting some Actionscript code from AS2 tp AS3, and I've eventually managed to get most of it to work again (it's allmost a totally different language, sharing just a little syntax similarity). One of the last things that still doesn't work, is the code for loading an external image.
Perhaps this has changed in AS3 but I really thought it was strange that to load an image you use loadVideo
, why not loadImage? (on the other hand a flash application is constantly called a flash video even when it's not used for animation at all). This doesn't work anymore, and what I've found is a pretty complex code that is said to replace this oneliner imageholder.loadVideo(url);
is this:
var urlreq:URLRequest = new URLRequest(url);
var theloader:Loader = new URLLoader();
theloader.load(urlreq);
theloader.addEventListener(Event.COMPLETE, function(event:Event):void {
imageholder.addChild(theloader);
}
);
But this doesn't work.. What I am doing wrong, and is there a more suited function to load images in AS3?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
人们在使用加载程序时遇到的最常见问题之一是他们监听事件的内容。 您需要确保您正在侦听大多数事件的 loader.contentLoaderInfo,而不是加载程序本身。 这是您提供的示例中的主要问题。
One of most common problems people have with loaders is what they listen to for events. You need to make sure you're listening to the loader.contentLoaderInfo for most events, not the loader itself. That was the main problem in the example you provided.
我认为你让事情变得有点太复杂了 - 这是加载单个图像所需的:
...你可以从那里推断加载图像列表吗? 在 for 循环中运行该代码,每次为新加载的 e.target.content 分配一个不同的变量(可能放在数组中,或者对象的属性中),以便您可以在“onComplete”类型之外访问它功能。
I think you're making things a little too complicated - here's what you need to load a single image:
... can you extrapolate from there to loading a list of images? Run that code in for-loop, each time assign a different variable (place in an array, perhaps, or property of an object) to your newly loaded e.target.content so you can access it outside of that 'onComplete'-type function.
我自己发现了一个解决方案。
初始化或卸载图像列表(实际上是 MovieClip 的实例):
当我需要更改图像时:
我也尝试添加一个列表器以使图像居中,但它似乎没有被调用? centerimage 函数做的第一件事是
trace("centerImage");
,它根本没有出现......I discovered a soulution, myself.
Initializing or unloading a list of images (actually instances of MovieClip):
when I need to change the image:
I tried to add a listner too to center the image, but it doesn't seem to get called? The first thing the centerimage function does is
trace("centerImage");
wich doesn't appear at all...