尝试测试xml as3脚本时出现此错误:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at xml_images_fla::MainTimeline/processXML()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
任何人都可以看到代码到目前为止是否工作不正常还是某个地方?
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.display.MovieClip;
import flash.events.Event;
import flash.display.Loader;
var columns:Number;
var my_x:Number;
var my_y:Number;
var my_thumb_width:Number;
var my_thumb_height:Number;
var my_images:XMLList;
var my_total:Number;
var container_mc:MovieClip;
var XMLLoader:URLLoader = new URLLoader();
XMLLoader.load(new URLRequest("gallery.xml"));
XMLLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void{
var myXML:XML = new XML(e.target.data);
columns = myXML.@COLUMNS;
my_x = myXML.@XPOSITION;
my_y = myXML.@YPOSITION;
my_thumb_width = myXML.@WIDTH;
my_thumb_height = myXML.@HEIGHT;
my_images = my_images.length();
createContainer();
callThumbs();
}
function createContainer():void{
container_mc = new MovieClip();
container_mc.x = my_x;
container_mc.y = my_y;
addChild(container_mc);
}
function callThumbs():void{
for (var i:Number = 0; i < my_total; i++){
var thumb_url = my_images[i].@THUMB;;
var thumb_loader = new Loader();
thumb_loader.load(new URLRequest(thumb_url));
thumb_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbLoaded);
}
}
function thumbLoaded(e:Event):void{
var my_thumb:Loader = Loader(e.target.loader);
container_mc.addChild(my_thumb);
}
答案 0 :(得分:2)
my_images = my_images.length();
那条线可能是你的问题。此时尚未定义my_images
。