renxiao2003 发表于 2011-12-21 08:44

1061: 调用可能未定义的方法 load

<DIV>
<DIV class="bct fc05 fc11 nbw-blog ztag">
<P style="TEXT-INDENT: 2em">AS3中用FileReference的load()方法加载本地图片,本文由AirSquare作。</P>
<P style="TEXT-INDENT: 2em">有很多朋友想加载本地文件,却苦于无法获取文件路径?<BR>&nbsp; &nbsp; 有很多朋友问到为什么API里FileReference有load()方法和data属性却不能使用?<BR>&nbsp; &nbsp;&nbsp; &nbsp;我也曾经有次困惑,但是如今解决了,现在与大家分享。<BR>&nbsp; &nbsp; 1、要想使用FileReference的load()方法和data属性需要使用flashplayer 10的版本,sdk3.5(sdk4.0肯定也可以,其他本版各位可以去试试),然后还要添加playerglobal.swc,在你所用的sdk包下面,我这里的路径是sdk3.5.0.12683/frameworks/libs/player/10/playglobal.swc,至此OK了,你再使用FileReference.load()或FileReference.data时就不会看到“<B style="BACKGROUND-COLOR: #ffff66; COLOR: black">调用可能未定义的方法</B>”等不舒服的字眼了,吼吼。<BR>&nbsp; &nbsp; 2、下面就可以用load()方法加载图片了<BR>&nbsp; &nbsp; var file:FileReference=new FileReference();<BR>&nbsp; &nbsp;&nbsp; &nbsp;var loader.loader=new Loader();<BR>&nbsp; &nbsp;&nbsp; &nbsp;private function onClick(e:MouseEvent):void<BR>&nbsp; &nbsp;&nbsp; &nbsp;{<BR>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; file.browse();<BR>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; file.addEventListener(Event.SELECT,onSelect);<BR>&nbsp; &nbsp;&nbsp; &nbsp;}<BR>&nbsp; &nbsp;&nbsp; &nbsp;private function onSelect(e:Event):void<BR>&nbsp; &nbsp;&nbsp; &nbsp;{<BR>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; file.load();<BR>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; file.addEventListener(Event.COMPLETE,onComplete);<BR>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; file.removeEventListener(Event.SELECT,onSelect);<BR>&nbsp; &nbsp;&nbsp; &nbsp;}<BR>&nbsp; &nbsp;&nbsp; &nbsp;private function onComplete(e:Event):void<BR>&nbsp; &nbsp;&nbsp; &nbsp;{<BR>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; file.removeEventListener(Event.COMPLETE,onComplete);<BR>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; loader.loadBytes(file.data);<BR>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoadComplete);<BR>&nbsp; &nbsp;&nbsp; &nbsp;}<BR>&nbsp; &nbsp;&nbsp; &nbsp;private function onLoadComplete(e:Event):void<BR>&nbsp; &nbsp;&nbsp; &nbsp;{<BR>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; var tempData:BitmapData=new BitmapData(loader.width,loader.height,<BR>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;false,null);<BR>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; tempData.draw(loader);<BR>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; var bitmap:Bitmap=new Bitmap(tempData);<BR>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; addChild(bitmap);<BR>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,<BR>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;onLoadComplete);<BR>&nbsp; &nbsp;&nbsp; &nbsp;}&nbsp;&nbsp;<BR></P></DIV></DIV>
页: [1]
查看完整版本: 1061: 调用可能未定义的方法 load