To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > Flash Help > Flash Newbies

Reply
 
Thread Tools Display Modes
Old 03-17-2010, 01:16 PM   #1
twaltz
Junior Member
 
Join Date: Mar 2010
Posts: 7
resolved [RESOLVED] CS4/XML/AS3 Addressing array nodes (unknown quantity)

I am working on a Flash application and need some assistance with elements of the AS3 code that handle the input from the xml file that holds the reading and questions about it. I'm parsing the .XML and loading it into Array variable(s). This works when I trace the variable "myxml" -- it shows everything nicely.

I'd like to know how to retrieve values of CIRCLING.QUESTION[i] and CIRCLING.ANSWER[i] from the variable "myxml" they have been parsed and loaded into, without getting an error message (because I won't know how many there are, I'm not sure how to write the loop controlling this...I think it's something to do with length but am not certain.

In English -- how do I display the questions that go with any particular sentence, since I don't know how many there are? The questions are also displayed on a different frame from the sentence they go with, if that matters.

Here is the xml input:
Code:
<?xml version="1.0" encoding="utf-8"?>

<STORY title="Cinderella">

<SENTENCE number="01">
	<ENGLISH>Cinderella is sad.</ENGLISH>
	<IMAGE>images/cinderella01</IMAGE>
	<AUDIO>cinderella01.mp3</AUDIO>
<CIRCLING>
//this one happens to have two questions; there could be up to 15//
	<QUESTION>
		<ENGLISH>Who is sad?</ENGLISH>
		<AUDIO>cin01Q01.mp3</AUDIO>
	<ANSWER>
		<ENGLISH>Cinderella is sad.</ENGLISH>
		<AUDIO>cin01A01.mp3></AUDIO>
	</ANSWER>
        </QUESTION>
	
	<QUESTION>
	<English>Why is she sad?</ENGLISH>
	<AUDIO<cin01Q02.mp3</AUDIO>
        <ANSWER>
            <ENGLISH>Because she has ugly sisters.</ENGLISH>
            <AUDIO>cin01A02.mp3></AUDIO>
           </ANSWER>
</CIRCLING>

</SENTENCE>


<SENTENCE>
<ENGLISH>Cinderella has two older sisters.</ENGLISH>
<IMAGE>images/cinderella02</IMAGE>
<AUDIO>cinderella02.mp3</AUDIO>

<CIRCLING>
//this one has only one question//
	<QUESTION>
		<ENGLISH>Who has two older sisters?</ENGLISH>
		<AUDIO>cin02Q01.mp3</AUDIO>
        <ANSWER>
	<ENGLISH>Cinderella does.</ENGLISH>
	<AUDIO>cin02A02.mp3></AUDIO>
	</ANSWER>
	</QUESTION>
</CIRCLING>
		
</SENTENCE>
</STORY>
The problem I'm having (as a person new to Flash and XML) is that there may be different numbers of questions under the <CIRCLING> nodes.

I would like to have a frame that displays all the questions under <CIRCLING>, one by one, in random order, in response to a button press each time, and displays/plays their corresponding answers and audio files, again in response to a button press, depending on which QUESTION is loaded. Repeats of the same question are ok but anyway the randomization is a later concern; for right now, I'd be happy just to get all the questions there might be under any particular SENTENCE.CIRCLING to display in turn.

I can code the buttons to make the content appear if I limit things to SENTENCE.CIRCLING.ENGLISH[0] and so forth (using specific integers, not variables in [ ]); my problem is how to load the XML elements for the <CIRCLING> content (making that [0] into an [i] or something for the loop) since I do not know how many child nodes <CIRCLING> might have for a given <SENTENCE>. There might be none, or there might be up to 15. (Something with "length" maybe? I've tried snippets from some Web sites and tutorials but so far no luck.)

Thank you greatly for any assistance!
twaltz is offline   Reply With Quote
Old 03-17-2010, 06:44 PM   #2
twaltz
Junior Member
 
Join Date: Mar 2010
Posts: 7
Got it.

It took a bit of fiddling around with the nested loops and the .length() thing, but it's working.
twaltz is offline   Reply With Quote
Reply

Tags
arrays, child, multidimensional array, xml

Go Back   Flash Kit Community Forums > Flash Help > Flash Newbies

Thread Tools
Display Modes

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 -4. The time now is 08:30 PM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.