PDA

View Full Version : Images displayed based on Array data


justmeadam
11-10-2006, 09:22 PM
I haven't seen this posted maybe someone has an example they could post. Let's say I have an Array with the data of "10", "20" and "30" and I have an image that corresponds to each of those values. I'm having trouble finding an example of displaying them.

So if I was passing %'s into a page and I had 1 image for every percent out of a 100 and wanted to post only the "percent image" for that value in the array how would it be done, that's the gist of it. I haven't seen anything out there doing that and it's making me a :( puppy. *buying lunch for the first poster!* umm if you come to Cali ....and have the small house salad... no croutons... :)

CDHBookingEdge
11-11-2006, 08:16 AM
No croutons? Mannn! Ok here ya go, try this out I tried it in Flexifier and it worked. If there was something I'm missing lemme know and LOL we'll talk croutons. ;-)


<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Script>
<![CDATA[
private var numberArray : Array = [10, 20, 30 ];
private function GetImageName(nNum:Number) : String
{
return String("Img" + numberArray[nNum] + ".jpg");
}
private function GetLabelText(nNum:Number) : String
{
return String("I would display" + GetImageName(nNum));
}
]]>
</mx:Script>
<mx:Grid >
<mx:GridRow>
<mx:GridItem colSpan="3">
<mx:Label text="Croutonless version" />
</mx:GridItem>
</mx:GridRow>
<mx:GridRow>
<mx:GridItem>
<mx:Label text="{GetLabelText(0)}" />
</mx:GridItem>
<mx:GridItem>
<mx:Label text="{GetLabelText(1)}" />
</mx:GridItem>
<mx:GridItem>
<mx:Label text="{GetLabelText(2)}" />
</mx:GridItem>
</mx:GridRow>
</mx:Grid>
</mx:Application>