-1

imgLoader在此 Flash AS3 应用程序上工作,当我尝试制作可点击时,我不断收到此错误。

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()
4

1 回答 1

0

调用它时是否会中断:

imgLoader.addEventListener(MouseEvent.CLICK, doSomething);

或者当它被调用时:

nextFrame()

在第一种情况下,imgLoader 为空。在第二种情况下,您在调用 nextFrame() 之后尝试访问字段或方法的内容为空。

编辑:

尝试移动这个:

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()
    }
}
于 2013-03-28T13:19:19.613 回答