在Flash中设置已加载图像的尺寸
如何在Flash中设置加载图像的宽度和高度?请求后立即设置尺寸不起作用。宽度和高度保持为零。
var poster:Loader = new Loader();
Stage.addChild(poster);
poster.load(new URLRequest('http://example.com/image.jpg'));
poster.width = 320;
poster.height = 240;
trace(poster.width); // 0
trace(poster.height); // 0
如果我等待片刻,然后设置尺寸,它将起作用。
我按照一些教程的建议,在调整大小之前尝试听Event.INIT
事件和Event.COMPLETE
事件。这两件事都没有被触发。
public function theClass() {
this.poster = new Loader();
this.poster.contentLoaderInfo.addEventListener(Event.INIT, this.imageLoaded);
this.poster.contentLoaderInfo.addEventListener(Event.COMPLETE, this.imageLoaded);
Stage.addChild(this.poster);
this.poster.load(new URLRequest('http://example.com/image.jpg'));
}
private function imageLoaded(event:Event):void {
trace('image is loaded');
this.poster.width = 320;
this.poster.height = 240;
}
没有找到相关结果
已邀请:
3 个回复
犯痪桂涛杭
倪蕊悲潍
在onComplete处理程序中,检查Loader.childAllowsParent以查看您是否有权访问加载程序内容。如果是这样,请设置loader.content.width和loader.content.height。
嫩昧竞莫
如果加载过程中存在问题,这就是您捕获它的方法。