user2421975
user2421975

Reputation: 197

Loading images from an array

I'm trying to load an image from an array, but I can't figure out how to do so...

For text, it's good :

private var textArray:Array = [
{label:"text1", Type:"it's the text1"},
{label:"text2", Type:"it's the text2"}]

and the function setDisplay is showing one of the label in my textField

private function setDisplay(e:Event):void{
var fIndex:int = ac.aIndex;
txtField.htmlText = "<b>Title:</b><br /> "  +  fruitArray[fIndex].Type;
txtField.setTextFormat(titleFormat);

Now I can't figure out how to do the same thing for images...

I've tried that :

private var possibleSources:Array = [
{label:"Image1", Image: {url:"assets/smiley.jpg"}},
{label:"Image2", Image: {url:"assets/smiley2.jpg"}}];

and add in my SetDisplay function :

txtField.htmlText = "<b>Title:</b><br /> "  +  textArray[fIndex].Type + "<b>Images:</b><br /> "  +  possibleSources.Image;

The app is launching and I've got "it's the text1" for text1 and "it's the text2" for text2

But for "Images" I've got "undefined".... Do you know what's wrong ?

Thank you for your help,

EDIT :

Thank you for your help.

Here's what I got so far :

private var possibleSources:Array = [
{label:"Image1", Image: {url:"assets/smiley1.jpg"}},
{label:"Image2", Image: {url:"assets/smiley2.jpg"}}];
private var textArray:Array = [
{label:"text1", Type:"It's the text1"},
{label:"text2", Type:"It's the text2"}]


private function setDisplay(e:Event):void{
it1.htmlText = "<b>Title :</b><br /> "  +  textArray[fIndex].Type +"<b>image :</b><br /> "  +  possibleSources[fIndex].Image.url;

And here's what I got as a result :

enter image description here

The smiley1.jpg is not here...

Upvotes: 0

Views: 42

Answers (1)

Nicolas Siver
Nicolas Siver

Reputation: 2885

You have mistake in code where you access data about Image in the possibleSources:

Correct:

 trace(possibleSources[0].Image.url);

Also, if you want display image in the text field, url string isn't enough, read about supported html tags, and their format.

Upvotes: 1

Related Questions