Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

[Director] Retreive info from a XML file

Status
Not open for further replies.

Royabbink

Technical User
Apr 22, 2005
2
NL
At the moment I'm working in Director MX. I want to retrieve information from a XML file into the Director stage. A text member should load the information from the XML file. I'm like this far:

The XML file:
I've tried to keep the XML file as easy as possible. The XML file is located in the same folder as the Director file. The content of the XML file (author.xml):
Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<author>
    <name>Mike Peterson</name>
</author>

The Director File:
The cast of the Director file (author.dir) contains 3 members:

1) A text member (name: author):
This member does not contain any code and it is located at frame 1 of the score.

2) A script member (behavior, name: xmlLoad):
This script is not located in the score, just in the cast. The member contains the following code:
Code:
property pXMLObj
global gNameAuthor 
 
on beginSprite me
  pXMLObj = new (xtra "XMLParser")
  pXMLObj.parseURL (the moviePath & "author.xml") 
end 
 
on endSprite me
  pXMLObj = 0
end 
 
on exitFrame me
  if pXMLObj.doneParsing () then
    gNameAuthor = pXMLObj.makeList ()
  else
    go the frame 
  end if 
end

3) A script member (parent, xmlParse):
This script is not located in the score, just in the cast. The member contains the following code:
Code:
global gNameAuthor 
 
on me
  member("author").text = gNameAuthor
end

What exactly is the problem?
I just want a text member to display the name "Mike Peterson" on the stage. Director should load the name from the XML file, but he doesn't. Director does not display any errors. Does anybody know how to fix this problem?
 
There are few problems in your code. The following movie script should accomplish what you want.

-- movie script
on prepareMovie
global gFileIO
gFileIO = new(xtra "FileIO")
gFileIo_OpenFile(the moviePath & "author.xml", 1)
tXMLStr = gFileIO.readFile()
gFileIO.closeFile()
gFileIO = VOID
global gXMLObj
gXMLObj = new(xtra "XMLParser")
gXMLObj.parseString(tXMLStr)
global gNameAuthor
gNameAuthor = gXMLObj.makeList()
gXMLObj = VOID
member("author").text = gNameAuthor[1].author.name["!CHARDATA"]
end prepareMovie
--

NB. I didn't put any error checking routine here but you should do that in your project. Also I wouldn't use makeList(), which will return ugly property list, but create my own property list from XML instead.

Kenneth Kawamoto
 
Thank you very much! It works!

I've another question, is it possible to read a URL (for example: images/image_01.jpg) from a XML file to use it as a reffer to a image? So I can change the image by edit the XML file?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top