[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How do I modify the first item in an xmlList?

Posted on 2009-02-17
5
Medium Priority
?
392 Views
Last Modified: 2013-11-11
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.
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>

Open in new window

0
Comment
Question by:worked
  • 2
  • 2
4 Comments
 

Author Comment

by:worked
ID: 23664014
Also, if it is easier to create the graphic in actionscript and replace the first item in the xmlList, then by all means please show me that method as well or instead.  My code below attempts this but displays [object Sprite] in the textfield instead of the graphic.  Any help is appreciated!  Thanks!
ACTIONSCRIPT:
var icon:Sprite = new Sprite();
icon.graphics.lineStyle(1, 0x000000);
icon.graphics.moveTo(0, 0);
icon.graphics.lineTo(-6, (-stage.stageHeight/2 + 2));
icon.graphics.moveTo(0, 0);
icon.graphics.lineTo(-6, stage.stageHeight/2 - 2);
icon.x = startPos - (spacer / 2);
icon.y = stage.stageHeight / 2;
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 +'">';
        // replace first item in list
        // xmlList[0].title = hi;  // this outputs [object Sprite] instead of the graphic.
        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);
}

Open in new window

0
 
LVL 8

Expert Comment

by:Dreammonkey
ID: 23665242
try this:

You can escape the ' and " characters by putting a \ before them...

DM
tf.htmlText = "<img src=\""+ xmlList[0].title +"\" >";

Open in new window

0
 

Author Comment

by:worked
ID: 23666669
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


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;
}

Open in new window

0
 
LVL 8

Accepted Solution

by:
Dreammonkey earned 1000 total points
ID: 23675729
I knows it sounds crazy but I found that adding a space in front of the string could solve things...


NOT:
img.htmlText = "<a href=\"" + textList[i].link + "\"><img src=\"" + textList[i].title + "\"></a>";
 
BUT:
img.htmlText = " <a href=\"" + textList[i].link + "\"><img src=\"" + textList[i].title + "\"></a>";

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month19 days, 11 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question