想问一下用xml加载图片(Bitmap)给一个容器(Sprite)后,再想读取容器的width是0,height也是0,我想读取容器的宽度怎么弄啊,可是当加载这个容器返回对象后读取不出这个容器的宽度,请问有什么方法吗?下面是我的代码:
- function loading(_url: String, _txt: String): MovieClip {
- var container: MovieClip = new MovieClip();
- var loader: Loader = new Loader();
- var url: URLRequest = new URLRequest(_url);
- loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onload);
- loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,error);
- loader.load(url);
- function error(e:IOErrorEvent):void{
- trace(e);
- }
- function onload(evt: Event): void {
- var image: Bitmap = Bitmap(loader.content);
- var w:Number=image.width;
- var h:Number=image.height;
- if(w/h<1){
- image.height=image_MaxHeight;
- image.width=w/h*image.height;
- }else{
- image.width=image_MaxWidth;
- image.height=h/w*image.width;
- }
- image.x=-image.width/2;
- image.y=-image.height/2;
- container.addChild(image);
- container["bg_width"]==image.width;//动态添加每一个容器的宽度,依然没有用?
- //trace(container.width);
- }
- return container;
- }
复制