2013-12-12 120 views
0

我在舞台上有一个按钮和进度条。我试图加载一个图像在闪光灯的同一个文件夹,但它没有工作。我收到以下错误:文件加载时出错

1119:通过 静态类型flash.net:URLLoader参考可能未定义的属性的contentLoaderInfo的访问。

和:

1067:的DisplayObject:类型flash.net:URLLoader对无关型flash.display使用一个值的隐式强制。

这里是我的代码:

import flash.net.URLLoader; 
import flash.net.URLRequest; 
import flash.events.Event; 
import flash.events.MouseEvent; 

var myLoader:URLLoader = new URLLoader(); 

btn_Img.addEventListener(MouseEvent.CLICK, uploadPic); 

function uploadPic(event:MouseEvent):void{ 
    myPb.source = myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoad); 
    myLoader.load(new URLRequest("myImage.png")); 
    btn_Img = null; 
     addChild(myPb); 
     removeChild(myPb); 
} 


function imageLoad(event:Event):void{ 
     addChild(myLoader); 
    btn_Img = null; 
} 

你能教我如何解决这个问题?我尝试了很多方法,但仍然没有把握好。

+0

此代码:myPb.source = myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,imageLoad);有点困惑。想要将侦听器定义与“myLoader”对象的源属性绑定? –

回答

0

contentLoaderInfo是Loader类的属性,而不是URLLoader的属性。另外,您无法将加载器本身传递给addChild--您需要添加加载的内容。最后,addEventListener不返回任何东西,所以myPb是一个无意义的变量。所以,你的代码应该是这个样子:

var myLoader:Loader = new Loader(); 

btn_Img.addEventListener(MouseEvent.CLICK, uploadPic); 

function uploadPic(event:MouseEvent):void{ 
    myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoad); 
    myLoader.load(new URLRequest("myImage.png")); 
} 


function imageLoad(event:Event):void{ 
    var loaded_image = BitMap(myLoader.content); // or whatever type the load is 
    addChild(loaded_image); 
} 

请注意,你不检查的负担,你可能要添加的以及错误。

有关更多详细信息,请参阅关于LoaderLoaderInfo的土坯帮助。