worked
asked on
How do I modify the first item in an xmlList?
Hey there-
I have a very simple for loop that parses an xml doc into textfields. Each textfield is added to a container within the loop for animation purposes later. Question. How do I modify the first item in the xmlList so that it displays an image instead of text? My code is below. Thanks! Any help is appreciated.
I have a very simple for loop that parses an xml doc into textfields. Each textfield is added to a container within the loop for animation purposes later. Question. How do I modify the first item in the xmlList so that it displays an image instead of text? My code is below. Thanks! Any help is appreciated.
ACTIONSCRIPT 3:
for (var i:int = 0; i < xmlList.length(); i++) {
var container:MovieClip = new MovieClip();
addChild(container);
var tf:TextField = new TextField();
tf.htmlText = xmlList[i].title;
//not working - tf.htmlText = '<img src="'+ xmlList[0].title +'">';
tf.autoSize = TextFieldAutoSize.CENTER;
tf.x = startPos;
tf.y = (stage.stageHeight / 2) - (tf.height / 2);
widthValue = tf.width;
container.path = xmlList[i].path;
container.addChild(tf);
container.addEventListener(MouseEvent.CLICK, onContainerDown);
startPos = startPos + (widthValue + spacer);
}
XML:
<?xml version='1.0' encoding='ISO-8859-1' ?>
<bc>
<item>
<title>image.gif</title>
<path>/</path>
</item>
<item>
<title>000000</title>
<path>/bc</path>
</item>
<item>
<title>000000</title>
<path>/bc/bc_1</path>
</item>
</bc>
try this:
You can escape the ' and " characters by putting a \ before them...
DM
You can escape the ' and " characters by putting a \ before them...
DM
tf.htmlText = "<img src=\""+ xmlList[0].title +"\" >";
ASKER
I had to place a dynamic textfield on the stage and load the graphic into that. I also used a nested for loop to display and position this graphic among the other textfields.
Question. Why can't I load a graphic into a textfield that is dynamically created, yet can load one into a dynamic textfield drawn on the stage?
For instance, where textList[i].link = image.gif
Question. Why can't I load a graphic into a textfield that is dynamically created, yet can load one into a dynamic textfield drawn on the stage?
For instance, where textList[i].link = image.gif
This WON'T load a graphic into a textfield:
var img:TextField;
for (var i:uint = 0; i < textList.length(); i++) {
img = new TextField();
img.htmlText = "<a href=\"" + textList[i].link + "\"><img src=\"" + textList[i].title + "\"></a>";
img.x = 0;
img.y = 0;
addChild(img);
}
However, this WILL load the graphic:
for (var i:uint = 0; i < textList.length(); i++) {
//load graphic into dynamic textfield on stage... named img
img.htmlText = "<a href=\"" + textList[i].link + "\"><img src=\"" + textList[i].title + "\"></a>";
img.x = 0;
img.y = 0;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Open in new window