Groups | Blog | Home
all groups > flash actionscript > march 2007 >

flash actionscript : Loading an image in an XML text file


GEORGEHAHN
3/20/2007 8:25:27 PM
I've gotten the DateChooser component to work very well loading dynamic text
fields with data from an external XML file. Can I embed a jpeg into the XML
text like I would with the <img> tag in an HTML text file?

Many thanks in advance for any tips...

George
Charles Parcell
3/20/2007 11:58:56 PM
You could have an attribute or a tag that would hold the path to the image.

<sometag>http://www.myDomain.com/images/myImage.jpg</sometag>

or

<sometag
img='http://www.myDomain.com/images/myImage.jpg'>somethingHere</sometag>
GEORGEHAHN
3/21/2007 12:07:45 AM
GEORGEHAHN
3/21/2007 12:17:44 AM
Below is the Actionscript that loads the XML file, putting data into 3 dynamic
text fields on the stage ("day_txt", "performer_txt" and "info_txt"). Ideally,
I'd want the image to be embedded in the "info_txt" text.

Thx.



myXML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = function(s){
if(s){
eventArray = [];
var children = this.firstChild.childNodes;
for(var c=0;c<children.length;c++){
var cEvent = children[c];
var cObj = {};
for(var d=0;d<cEvent.childNodes.length;d++){
var node = cEvent.childNodes[d];
var field = node.nodeName;
var value = node.firstChild.nodeValue;
cObj[field] = value;
}
eventArray[cEvent.attributes.date] = cObj;
}
myDC.enabled = true;
}else{
trace('Error loading file!');
}
}
myXML.load('showcalendar.xml');
myDC.enabled = false;
myDC.change = function() {
var d = this.selectedDate;
var d_str = (d.getMonth()+1)+'/'+d.getDate()+'/'+d.getFullYear();
var cEvent = eventArray[d_str];
day_txt.text = '';
performer_txt.text = '';
info_txt.text = '';
if(cEvent){
for(var obj in cEvent){
this._parent[obj+'_txt'].text = cEvent[obj];
}
}
};
myDC.addEventListener('change', myDC);
Charles Parcell
3/21/2007 8:09:29 PM
I assume your XML looks something like this...

<event date='11/11/1111'>
<PerformerName>SomeInfoHere</PerformerName>
</event>

You could add the image info anywhere you want in the XML. Perhaps an
attribute of the PerformerName tag?

<PerformerName image='myImage.jpg'>SomeInfoHere</PerformerName>

or

<PerformerName
image='http://www.myDomain.com/images/myImage.jpg'>SomeInfoHere</PerformerName>

When you parse the XML data and build your Array, then you just need to
capture the additional tag attribute. Similar to how you got the date attribute.

Then at that point you would add it into the textField of your info_txt.

Read this page in the docs to see how to add the image.
http://livedocs.adobe.com/flash/8/main/00001464.html

AddThis Social Bookmark Button