PDA

View Full Version : TypeError


The Little Guy
01-23-2009, 04:40 AM
I am getting this error, and Im not sure what it really means:
null
TypeError: Error #1010: A term is undefined and has no properties.
at GMScores/loadXML()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunctio n()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/flash.net:URLLoader::onComplete()

In my fla file I have this:
import GMScores;
var scores:GMScores = new GMScores();
var gameStamp = '0gwl9i1hflry8anvtk7hpc4fi3ojmtj';
var gameID = '1';

trace(scores.getScores(gameStamp,gameID));

Then I have the class its self, which looks like this:
package {
import flash.display.Sprite;
import flash.events.*;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
import flash.xml.*;

public class GMScores extends Sprite{
public var scores = new Array();
public var xmlData:URLLoader = new URLLoader();
public var xDoc:XMLDocument = new XMLDocument();
public function getScores(gameStamp,gameID):Array{
xmlData.load(new URLRequest("http://gmserver.publicsize.com/xml/"+gameStamp+"/"+gameID));
scores = xmlData.addEventListener(Event.COMPLETE, loadXML);
return scores;
}
public function loadXML(e:Event):Array{
xDoc.ignoreWhite = true;
var mXML:XML = XML(xmlData.data);
xDoc.parseXML(mXML.toXMLString());
for(var i = 0;i<xDoc.firstChild.childNodes.length;i++){
scores[i] = new Array();
scores[i][0] = xDoc.firstChild.childNodes[i].childNodes[0].firstChild;
scores[i][1] = xDoc.firstChild.childNodes[i].childNodes[1].firstChild;
}
return scores;
}
}
}

Cota
01-23-2009, 04:55 AM
I would say your XML is returning empty nodes. I actually just delt with this issue today as well. I was running a conditional check on a node that wasnt in the XML. So I'd say double check the node paths.

The Little Guy
01-23-2009, 05:07 AM
I just got rid of that...
by changing this:
scores = xmlData.addEventListener(Event.COMPLETE, loadXML);
to this:
xmlData.addEventListener(Event.COMPLETE, loadXML);

Now I am not sure how I can return the array in getScores...

xxneon
01-23-2009, 05:22 AM
there is a few things you need to do to make it work the way you want it to..
the error was caused by this line..
scores = xmlData.addEventListener(Event.COMPLETE, loadXML);
the reason is .. you have scores storing the return value of addEventListener().. and it doesn't return anything .. so this line was assigning null to scores.. and then erasing the new Array() that was stored in the constructor..

ok .. knowing that now it was storing 'null' explains why in your loadXML function it was giving you the error .. because you have a for loop that was trying to assign new arrays to the scores array indexes..
scores[i] = new Array();
since scores is null... then this line would give you your error..

null[i] = ... see what i mean..

ok now to the code that i have to make it trace out right ..
in the fla..
import GMScores;
var scores:GMScores = new GMScores();
var gameStamp = '0gwl9i1hflry8anvtk7hpc4fi3ojmtj';
var gameID = '1';

scores.getScores(gameStamp,gameID);
and my modified version of your class..
package {
import flash.display.Sprite;
import flash.events.*;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
import flash.xml.*;

public class GMScores extends Sprite{
public var scores = new Array();
public var xmlData:URLLoader = new URLLoader();
public var xDoc:XMLDocument = new XMLDocument();
public function getScores(gameStamp,gameID){
xmlData.load(new URLRequest("http://gmserver.publicsize.com/xml/"+gameStamp+"/"+gameID));
xmlData.addEventListener(Event.COMPLETE, loadXML);
}
public function loadXML(e:Event){
xDoc.ignoreWhite = true;
var mXML:XML = XML(xmlData.data);
xDoc.parseXML(mXML.toXMLString());
for(var i = 0;i<xDoc.firstChild.childNodes.length;i++){
scores[i] = new Array();
scores[i][0] = xDoc.firstChild.childNodes[i].childNodes[0].firstChild;
scores[i][1] = xDoc.firstChild.childNodes[i].childNodes[1].firstChild;
}
trace(scores);
}
}
}
if you want to be able to retreive the scores from the timeline you need to extend your class to EventDispatcher.. so that your class can dispatch events .. and then inside your loadXML you can simply dispatch an Event.COMPLETE .. and have a listener setup on your timeline .. and then retreive the scores array from the GMScores instance.. hope that makes sense..

The Little Guy
01-23-2009, 05:34 AM
OK... I don't want my class to trace out the code, I would like it to trace out in the fla file... so what you did was reverse what I wanted.

In the end I need to distribute this class to people so they can use it in their fla files.

xxneon
01-23-2009, 05:59 AM
which is what i was getting at in the end of my post..

here this is what your looking for..
FLA
import GMScores;
var scores:GMScores = new GMScores();
var gameStamp = '0gwl9i1hflry8anvtk7hpc4fi3ojmtj';
var gameID = '1';


scores.addEventListener(Event.COMPLETE,get_scores) ;
scores.getScores(gameStamp,gameID);


function get_scores(e:Event){
trace("from fla: - " + e.target.scores);
}

Class..
package {
import flash.display.Sprite;
import flash.events.*;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
import flash.xml.*;

public class GMScores extends Sprite{
public var scores = new Array();
public var xmlData:URLLoader = new URLLoader();
public var xDoc:XMLDocument = new XMLDocument();
public function getScores(gameStamp,gameID){
xmlData.load(new URLRequest("http://gmserver.publicsize.com/xml/"+gameStamp+"/"+gameID));
xmlData.addEventListener(Event.COMPLETE, loadXML);
}
public function loadXML(e:Event){
xDoc.ignoreWhite = true;
var mXML:XML = XML(xmlData.data);
xDoc.parseXML(mXML.toXMLString());
for(var i = 0;i<xDoc.firstChild.childNodes.length;i++){
scores[i] = new Array();
scores[i][0] = xDoc.firstChild.childNodes[i].childNodes[0].firstChild;
scores[i][1] = xDoc.firstChild.childNodes[i].childNodes[1].firstChild;
}
dispatchEvent(new Event(Event.COMPLETE));
}
}
}
since you extend Sprite.. you can dispatch events ... since Sprite inherits functionality of EventDispatcher..

The Little Guy
01-23-2009, 06:31 AM
Perfect! Thanks for the help!