TwelvestoneFlash

Flash MX, XML and confusion


Sign in

  • Waiting for Godot ( 730 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 5.1 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.9 k posts )
    general front end design an...
  • Back End ( 9.7 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
Technomancer
 
2003-02-04

Hi all,

In response to my question here I have chosen to go the Flash/XML route.

First off, the last time I did any flash work was with Flash 4, so I am not overly familiar with MX. Second I have never looked at XML before.

I have created my XML data and am trying to populate some text fields from it. My xml looks like this:

<?xml version"1.0" encoding="UTF-8" ?> a dog a cat a mouse a pig a dog a cat a mouse a pig a dog a cat a mouse a pig

I have some AS on the first frame of the first layer and 4 dynamic text fields also on the first frame but on a separate layer (named: "question", "option_1", "option_2", "option_3", "option_4").

At this moment all I am trying to do is load the xml file (which works as I have traced it) and then populate the above fields.

The fields remain unpopulated. Can anyone tell me why?

questions_xml = new XML(); questions_xml.ignoreWhite = true; questions_xml.onLoad = function(success) { if (success) { do_Questions(questions_xml); } }; questions_xml.load('data/questions.xml');

function do_Questions(xmlDoc_xml) { _root.question = xmlDoc_xml.firstChild.childNodes[0].attributes["text"]; _root.option_1 = xmlDoc_xml.firstChild.childNodes[0].childNodes[0].nodeValue; _root.option_2 = xmlDoc_xml.firstChild.childNodes[0].childNodes[1].nodeValue; _root.option_3 = xmlDoc_xml.firstChild.childNodes[0].childNodes[2].nodeValue; _root.option_4 = xmlDoc_xml.firstChild.childNodes[0].childNodes[3].nodeValue; }

Thanks for any help, having managed to load the XML data I am now completely lost!

If it helps the fla is here

Techno~

persist
 
2003-02-04

you need to refer to the text attribute of the new MX text field object.

Also you were not addressing the correct xml nodes, and instead were referring to node values, which can be misleading, as really this is a value based on the type of node it is, rather than it's content. Flash does not need brackets to discern a child node, so you can refer the inner content as another child.

try this:

questions_xml = new XML(); questions_xml.ignoreWhite = true; questions_xml.onLoad = function(success) { if (success) { do_Questions(questions_xml); } }; questions_xml.load('data/questions.xml');

function doQuestions(xmlDoc_xml) { _root.question.text = xmlDoc_xml.firstChild.childNodes[0].attributes.text; for(i = 0;i<5;i++){ _root["option"+(i+1)].text = xmlDoc_xml.firstChild.childNodes[0].childNodes[i].childNodes; } }

Technomancer
 
2003-02-04

Thanks persist,

that works a treat.

I've just realised exactly how ring-rusty I am with Flash, let alone trying to get to grips with XML.

Techno~

persist
 
2003-02-04

I made a super raw and ugly xml-flash fla, to show a freind one night how to construct a menu, and one way to associate the xml content with the menu. It's been a popular download.

It's here. It's damn ugly, but it's code is commented, and it's a basic introduction to building flash content based on xml file structure.

http://www.pixelplay.org/jeff/LEN

k

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneFlash

Flash MX, XML and confusion