0

Getting this error when I try to test the xml as3 script:

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

Can anyone see if the code is so far not working properly or is it somewhere esle?

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);
}
1
  • Can you post some of(if not all of) your xml. Also on a separate note, you should rename your variables from this my_thumb_width to this myThumbWidth or better yet this thumbWidth. Also XMLLoader should be xmlLoader. Finally it might be better to rename your processXML() event handler to onXmlLoaderComplete() or onXMLLoaderComplete(). Also you might want to consider writing your code in the document class as opposed to the timeline. Commented May 17, 2011 at 20:46

1 Answer 1

2
my_images = my_images.length();

That line is probably your issue. my_images isn't defined yet at this point.

Sign up to request clarification or add additional context in comments.

7 Comments

Oh thats supposed to be my_total = my_images.length(); but still get the error. I'm guessing its still undefined.
Yah, my_images doesn't get defined anywhere as far as I can see.
yes, but you're trying to get the length of my_images. So if my_images is null, you get the error.
Ok then I'm guessing I missed something out of the tutorial or they missed that part so far before telling me to test.
I have my_total in the for loop. Does that still mean it's undefined?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.