It depends on what you're wanting to do with it.
It sounds like you're wanting an image of tomatoes to be next to the tomatoes text field, an image of cabbage next tothe cabbage one, and likewise for chocolate. At first the user can't see any of the images, but when the user types anything at all in one of those text fields, the image next to it suddenly shows up. Is this so?
If that's the case, then one of the simplest (though not the most efficient) ways to do this is to go ahead and add those images next to the text fields normally, just as though they show up all throughout the program. Go ahead and position them all right where they're going to go, size them, everything. The only difference here is that you want to set each one of their visible
properties to false
.
Then you could either have a separate function handling each text field's event listener, or you could have that switch statement you're talking about in just one function that handles all three of those text fields. Then:
private function onChange(event:Event):void
{
if (event.target.text != "")
{
switch (event.target)
{
case txtTomatoes:
imgTomatoes.visible = true;
break;
case txtCabbage:
imgCabbage.visible = true;
break;
case txtChocolate:
imgChocolate.visible = true;
}
}
}
This is only one way to do this, and it depends on where you're wanting to go with it.