Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 09-30-2011, 06:48 PM   #1
dburwell
Senior Member
 
Join Date: Feb 2001
Posts: 127
Default help with XML

I'm currently converting an AS2 project to AS3 and need a little help with XML. I've got it reading the file fine, but for some dumb reason I can't set a variable from the data received. I get this message when testing...

TypeError: Error #1010: A term is undefined and has no properties.
at TestXML_fla::MainTimeline/LoadXML()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()

Here's my code (attached also)...

import flash.net.URLLoader;
import flash.net.URLRequest;

var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();

xmlLoader.addEventListener(Event.COMPLETE, LoadXML);

xmlLoader.load(new URLRequest("TKread.xml"));

ActionScript Code:
function LoadXML(e:Event):void {     var xml:XML;     xml = new XML(e.target.data);     xml.ignoreWhitespace = true;     trace(xml);     //returns first TK element     trace("Number of TKs: "+ xml.TKprs[0].TKnum);     var Crap:Number = xml.Tkprs[0].TKnum;     //trace(Crap); } stop();

The variable "Crap" is where I get the error.

This is probably so easy but I've already converted tons of code and just can't get this one.

Thanks for being nice to the "virgin"...
Attached Files
File Type: zip TestXML.zip (6.9 KB, 34 views)
dburwell is offline   Reply With Quote
Old 09-30-2011, 06:51 PM   #2
dburwell
Senior Member
 
Join Date: Feb 2001
Posts: 127
Default

Sorry, got my wrappers wrong. Also meant to say that it traces fine, just can't get it to a variable...

ActionScript Code:
import flash.net.URLLoader; import flash.net.URLRequest; var xmlLoader:URLLoader = new URLLoader(); var xmlData:XML = new XML(); xmlLoader.addEventListener(Event.COMPLETE, LoadXML); xmlLoader.load(new URLRequest("TKread.xml")); function LoadXML(e:Event):void {     var xml:XML;     xml = new XML(e.target.data);     xml.ignoreWhitespace = true;     trace(xml);     //returns first TK element     trace("Number of TKs: "+ xml.TKprs[0].TKnum);     var Crap:Number = xml.Tkprs[0].TKnum;     //trace(Crap); } stop();
dburwell is offline   Reply With Quote
Old 09-30-2011, 06:56 PM   #3
PBFrO
Senior Member
 
Join Date: Jan 2007
Location: Orange County, CA
Posts: 573
Default

does the trace before that display anything?
__________________
My Portfolio
PBFrO is offline   Reply With Quote
Old 09-30-2011, 06:57 PM   #4
dburwell
Senior Member
 
Join Date: Feb 2001
Posts: 127
Default

Yes it does, exactly what I'm looking for - that's why I'm stumped. It's the same exact reference...
dburwell is offline   Reply With Quote
Old 09-30-2011, 07:14 PM   #5
PBFrO
Senior Member
 
Join Date: Jan 2007
Location: Orange County, CA
Posts: 573
Default

Give this a try...also making some changes to your code.

ActionScript Code:
import flash.net.URLLoader; import flash.net.URLRequest; var xmlLoader:URLLoader = new URLLoader(); var xmlData:XML; xmlLoader.addEventListener(Event.COMPLETE, LoadXML); xmlLoader.load(new URLRequest("TKread.xml")); function LoadXML(e:Event):void {     xmlData = new XML(e.target.data);     xmlData.ignoreWhitespace = true;     trace(xmlData);     //returns first TK element     trace("Number of TKs: "+ xmlData.TKprs[0].TKnum);     var Crap:Number = xmlData.Tkprs[0].TKnum;     //trace(Crap); } stop();
__________________
My Portfolio

Last edited by PBFrO; 09-30-2011 at 07:16 PM. Reason: Full code change
PBFrO is offline   Reply With Quote
Old 09-30-2011, 07:27 PM   #6
dburwell
Senior Member
 
Join Date: Feb 2001
Posts: 127
Default

Nope... Same error. This is when I do a "Control, Test Move" BTW.

It will trace the XMLData that is loaded...

It will trace the "Number of TKs: " + xmlData.TKprs[0].TKnum

But it won't let me define a variable and give it the exact same parameters.

Strange, very strange indeed!!!
dburwell is offline   Reply With Quote
Old 09-30-2011, 07:51 PM   #7
sparX
!Senior Member
 
Join Date: Jan 2010
Posts: 1,675
Default

If 'TKprs' gives you the right property, then why are you trying to assign 'Tkprs'?
sparX is offline   Reply With Quote
Old 09-30-2011, 07:56 PM   #8
dburwell
Senior Member
 
Join Date: Feb 2001
Posts: 127
Default

because it "traces" the information correctly, when I try to assign the exact same info to a variable, it errors out. I need the variables elsewhere in the program.

make sense???

maybe I'm confused as to what you are asking.
dburwell is offline   Reply With Quote
Old 09-30-2011, 07:59 PM   #9
sparX
!Senior Member
 
Join Date: Jan 2010
Posts: 1,675
Default

I'll make it easier for you...

Does TKprs = Tkprs?
sparX is offline   Reply With Quote
Old 09-30-2011, 08:03 PM   #10
dburwell
Senior Member
 
Join Date: Feb 2001
Posts: 127
Default

Okay, just call it Friday stupidity to the max, lay off the crack moment.

Duh... I had the K in TKnum as lower case. What an idiot...

When I retyped everything it worked fine, then I said what's going on and finally saw it. Darn K's look too much alike...
dburwell is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:30 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.