mercredi 23 septembre 2015

When attempting to import an XML file into Flash I get a TypeError: Error #1009: Cannot access a property or method of a null object reference.

this is my first post on here. So I will try and be precise with what my problem is. I trying to import an XML files data into some dynamic text boxes in Adobe Flash. I did this for part of my final project, so thought this would be easy. Although I seem keep getting the same error message. Any chance you take a look and give me some feedback please. The code is split up into 3 parts:

var sums;

var currentAddition:addition;

var sumNumber = 0;

begin();



 function begin():void{

loadXMLFile();


}

function loadXMLFile():void{



var xmlLoader:URLLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
xmlLoader.load(new URLRequest("addition.xml"));
}

function onComplete(e:Event):void{

var xmlData:XML = new XML(e.target.data);
xmlData.ignoreWhitespace = false;
trace(xmlData);
extractNumbers(xmlData);
}

function extractNumbers(xmlData):void{


var sumsXML:XMLList = xmlData.additions;
var number_of_sums:uint = sumsXML.length();
sums = new Sum_A(); 
var additions:addition;

     for(var i:uint = 0; i < number_of_sums; i++){

    additions = new addition();     

    additions.number_A = sumsXML[i].number_A.text();
    additions.number_B = sumsXML[i].number_B.text();
    additions.option_01 = sumsXML[i].option_01.text();
    additions.option_02 = sumsXML[i].option_02.text();
    additions.option_03 = sumsXML[i].option_03.text();
    additions.option_04 = sumsXML[i].option_04.text();



    sums.addSum(additions);


    }
    sums.displaySums();
    getNextSum();

    }



function displayNextSum():void{

getNextSum();


 }

function getNextSum():void{

trace("Got next person");

var additions:addition = sums.getNextSum();

input_01.text = additions.number_A;
input_02.text = additions.number_B;
options_all.option_01.text = additions.option_01;
options_all.option_02.text = additions.option_02;
options_all.option_03.text = additions.option_03;
options_all.option_04.text = additions.option_04;

currentAddition = additions;

sumNumber = sumNumber +1;

}   

The other two serparate AS3 files: Sum_A

 package 
{


public class Sum_A{

    public var sums:Array
    private var sum_number:uint;


    public function Sum_A(){

        sums = new Array();
        sum_number = 0;


        }

    public function addSum(additions:addition):void{

    sums.push(additions);
        }

    public function getNextSum():addition{

    if (sum_number < sums.length){

        return sums[sum_number++];

    }
    else{

        resetSums();

        }


    return sums[sum_number];


    }

public function resetSums():void{

    sum_number = 0;

}





}

}

addition:

package {


public class addition{

    public var number_A:String;
    public var number_B:String;
    public var option_01:String;
    public var option_02:String;
    public var option_03:String;
    public var option_04:String;



    public function addition(){



    }






}



}   

Thank you for guys taking the time to look through it all for me.

Aucun commentaire:

Enregistrer un commentaire