使用此Flash AS3应用程序,当我尝试点击imgLoader
时,我一直收到此错误。
imgLoader是一个动态加载器,它将从XML文件加载图像,并使用ActionScript创建它。
这是我得到的完整错误:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at apptest_fla::MainTimeline/frame1()[apptest_fla.MainTimeline::frame1:65]
at runtime::ContentPlayer/loadInitialContent()
at runtime::ContentPlayer/playRawContent()
at runtime::ContentPlayer/playContent()
at runtime::AppRunner/run()
at ADLAppEntry/run()
at global/runtime::ADLEntry()
这是使imgLoader
可点击的代码:
imgLoader.addEventListener(MouseEvent.CLICK, doSomething);
function doSomething(event:MouseEvent){
nextFrame()
有谁知道为什么会这样?
修改
这是我的全部代码:
stop();
import flash.display.Loader;
import flash.events.Event;
import flash.net.URLRequest;
import flash.display.Sprite;
import flash.filters.DropShadowFilter;
var xmlLoader11:URLLoader;
var xml11:XML;
var uRequest11 = new URLRequest("my.xml");
xmlLoader11 = new URLLoader(uRequest11);
xmlLoader11.addEventListener(Event.COMPLETE, onXMLLoad11);
var imgLoader11:Loader;
var nameLoader11:Loader;
var myString11:String = 'loading';
function onXMLLoad11(e:Event) {
xml11 = new XML(e.target.data);
imgLoader11 = new Loader();
imgLoader11.contentLoaderInfo.addEventListener(Event.COMPLETE, onImgLoaded11);
imgLoader11.load(new URLRequest(xml11.Data.Image.text()[0]));
Nametxt11.text = "" + xml11.Data.Name.text()[0];
}
function onImgLoaded11(e:Event) {
addChild(imgLoader11);
imgLoader11.height = 300;
imgLoader11.width = 300;
var bitmapContent11:Bitmap = Bitmap( e.target.content );
bitmapContent11.smoothing = true;
addChild( bitmapContent11 );
bitmapContent11.height = 150;
bitmapContent11.width = 150;
bitmapContent11.y = 65;
bitmapContent11.x = 85;
}
imgLoader11.addEventListener(MouseEvent.CLICK, doSomething);
function doSomething(event:MouseEvent){
nextFrame()
答案 0 :(得分:0)
调用它时是否会中断:
imgLoader.addEventListener(MouseEvent.CLICK, doSomething);
或在调用时:
nextFrame()
在第一种情况下,imgLoader为null。在第二种情况下,在调用nextFrame()之后,您尝试访问字段或方法的内容为null。
编辑:
尝试移动它:
imgLoader11.addEventListener(MouseEvent.CLICK, doSomething);
function doSomething(event:MouseEvent){
nextFrame()
}
到onXMLLoad11()的底部。
function onXMLLoad11(e:Event) {
xml11 = new XML(e.target.data);
imgLoader11 = new Loader();
imgLoader11.contentLoaderInfo.addEventListener(Event.COMPLETE, onImgLoaded11);
imgLoader11.load(new URLRequest(xml11.Data.Image.text()[0]));
Nametxt11.text = "" + xml11.Data.Name.text()[0];
imgLoader11.addEventListener(MouseEvent.CLICK, doSomething);
function doSomething(event:MouseEvent){
nextFrame()
}
}