PDA

View Full Version : Super Basic (I think) xml and AS 3.0 question



tronoku
March 29th, 2009, 01:22 AM
Hi, I am a front-end developer that is just getting into flash and AS 3.0.

I have a basic question..
First, let me explain the situation.

I have a php script that grabs data from a sql database and stores it into an XML file, this data is then read by a flash doc which should show the different values based on the movie.

I have successfully loaded the xml doc into my flash and have been able to traverse the xml dom thanks to a tutorial on this website. (thank you for that, it was a very in depth helpful tutorial found here http://www.kirupa.com/developer/flashcs3/using_xml_as3_pg7.htm (http://www.kirupa.com/forum/../developer/flashcs3/using_xml_as3_pg7.htm))

Now, here is my issue. I have successfully used trace to call out information into the "output" window.. But I cannot for the life of me figure out how to put this information into my dynamic text box.

After a bit of looking around I found out that I create a dynamic text box to input text. (like a said.. I am new to flash entirely)

So I created a dynamic text box and typed in text_1 into the box underneat it. (I can only assume that this is the name of the text box)

So then I used the action script text_1.text = nodeText.node.text.text()[0];

But this comes up with some errors..

Please let me know if I need to give anymore information.

Thanks,

Jeff

My xml is very simple..


<?xml version="1.0" encoding="ISO-8859-1"?>
<document>
<node>
<text>Sample Text1</text>
</node>
<node>
<text>Sample Text2</text>
</document>


And here is my action script code:


var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("note.xml"));
function LoadXML(e:Event):void {
xmlData = new XML(e.target.data);
ParseData(xmlData);
}
function ParseData(nodeText:XML):void {
text_1.text = nodeText.node.text.text()[0];
}

snickelfritz
March 29th, 2009, 01:29 AM
<?xml version="1.0" encoding="ISO-8859-1"?>
<document>
<node>
<text>Sample Text1</text>
</node>
<node>
<text>Sample Text2</text>
</node>
</document>

tronoku
March 29th, 2009, 02:14 AM
Not sure what you are saying snickle,

Can anyone help me out with this? I am trying to finish this by tonight... Please help

tronoku
March 29th, 2009, 05:36 AM
Not sure what you are saying snickle,

Can anyone help me out with this? I am trying to finish this by tonight... Please help

Well I fixed the AS problem, but now I have another problem..

For some reason when I try and load the information into my dynamic text area.. while the text is inside a movie clip I get an AS error:


1120: Access of undefined property text_1.
From the code:

text_1.text = xmlData.node.text.text()[0];

Anyone have a solution?
The reason why it is in a movie clip is so that I can fade the text in and out..

For now I think I am just going to create a black object on top of the text and change the opacity so that it gives the effect of fading in and out.

Any suggestions? I was thinking that it may have something to do with the way I am storing the text? I am really at a loss for solutions.

Sure hope someone reads this thread,

Jeff

Gnoll
March 29th, 2009, 06:28 AM
1120: Access of undefined property text_1. means text_1 doesn't exist, if you are dragging this textfield onto the stage make sure it is set to dynamic text, and the instance name is text_1

tronoku
March 29th, 2009, 06:34 AM
Well it does exist, it is just that it is inside of a movie clip which is on the stage.

I am looking into something called tweenmax.. But I can't find any documentation on it.. I have never used classes before, if anyone knows how to start using this.. or any good documentation on classes/tweenmax it would help

Valaran
March 29th, 2009, 06:36 AM
Just like what you did with the textfield, you have to assign a instance name to the MovieClip, and to point inside the MovieClip (Display objects like MovieClip's and Sprite's have a scope of their own), so what you want to be doing is


movieclipinstance.text_1.text = node...

tronoku
March 29th, 2009, 07:36 AM
Valaran, if I knew or cared to know where you lived, I would fly over and kiss you!

I have spent about 4 hours trying to get this thing to work.. I even went out and tried to learn tweenmax (thinking that it would allow me to tween the text object), thank you so much. I think I am going to hit the sack now.. My brain isn't working very well anymore hehe..

snickelfritz
March 29th, 2009, 11:38 AM
Not sure what you are saying snickle,

Can anyone help me out with this? I am trying to finish this by tonight... Please help

Your XML is missing the last closing </node>:


<?xml version="1.0" encoding="ISO-8859-1"?>
<document>
<node>
<text>Sample Text1</text>
</node>
<node>
<text>Sample Text2</text>
</document>

I posted a corrected version.