PDA

View Full Version : displaying array & looping


docwisdom
07-28-2009, 12:07 AM
I got my data into my calculations and I have created a new array with the calculated data. I was using a repeater with the dataprovider as my arraycollection. Now that I am using a simple array, what is the best way to display each element from that array in the flex layout?
I also need to loop through all of the objects in the array collection, do the calculations and repeat the layout for each object.

thanks!!

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="1920" height="1080"
creationComplete="init();" borderColor="#797979" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#636363, #9A9A9A]" color="#F3F3F3">
<mx:Script>
<![CDATA[
import mx.controls.Text;
import mx.controls.Label;
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
import mx.utils.ObjectUtil;
import flash.display.Shape;
import flash.utils.Timer
import flash.events.TimerEvent
import flash.display.Sprite
import flash.geom.Rectangle
private function init():void
{
inventoryService.send();
dbTimer();
}
[Bindable]
private var omArray:ArrayCollection
private function resultHandler(event:ResultEvent):void
{
omArray = event.result.response.data.row;
performCalc();
}

private function dbTimer():void
{
var mTimer:Timer=new Timer(10000)
mTimer.addEventListener(TimerEvent.TIMER,Comple);
mTimer.start();
}
private function Comple(e:TimerEvent):void
{
inventoryService.send();
}
private function performCalc():Array
{
var omMachineRecord:Object = omArray.getItemAt(2);
if (omMachineRecord.om_status == 1) {
trace("omStack.selectedIndex = 1");
}
else {
omStack.selectedIndex = 0
}
if (omMachineRecord.os_status == 1) {
trace("osStack.selectedIndex = 1");
}
else {
osStack.selectedIndex = 0
}
var retRID:Number = omMachineRecord.recycler_id;
var retLocation:String = omMachineRecord.location;
var retTotal:Number = omMachineRecord.total;
var coinGPercent:int = (omMachineRecord.coin_G/omMachineRecord.coin_G_MAX)*100
var coinEPercent:int = (omMachineRecord.coin_E/omMachineRecord.coin_E_MAX)*100
var coinDPercent:int = (omMachineRecord.coin_D/omMachineRecord.coin_D_MAX)*100
var coinCPercent:int = (omMachineRecord.coin_C/omMachineRecord.coin_C_MAX)*100
var coinBPercent:int = (omMachineRecord.coin_B/omMachineRecord.coin_B_MAX)*100
var coinAPercent:int = (omMachineRecord.coin_A/omMachineRecord.coin_A_MAX)*100
var billDPercent:int = (omMachineRecord.bill_D/omMachineRecord.bill_D_MAX)*100
var billCPercent:int = (omMachineRecord.bill_C/omMachineRecord.bill_C_MAX)*100
var billBPercent:int = (omMachineRecord.bill_B/omMachineRecord.bill_B_MAX)*100
var billFPercent:int = (omMachineRecord.bill_F/omMachineRecord.bill_F_MAX)*100
var retArray:Array = new Array(retRID,retLocation,coinGPercent,coinEPercent ,coinDPercent,coinCPercent,co inBPercent,coinAPercent,billDPercent,billCPercent, billBPercent,billFPercent,retT otal);
trace(retArray);
return retArray
}
]]>
</mx:Script>
<mx:HTTPService id="inventoryService"
url="http://localhost/OMRON-debug/RCM_INVENTORY.php?method=FindAll"
result="resultHandler(event)"/>
<mx:VBox width="1900" height="1060" x="10" y="10" borderColor="#7F8081">
<mx:ToggleButtonBar dataProvider="{mainStack}"/>
<mx:ViewStack id="mainStack" width="100%" height="100%">
<mx:HBox label="OVERVIEW" width="100%" height="100%">
<mx:Tile width="100%" height="100%">
<mx:Repeater id="omRepeater" dataProvider="{performCalc(p)}">
<mx:VBox width="262" height="353" borderStyle="solid" borderColor="#B7BABC">
<mx:VBox width="100%">
<mx:HBox width="100%">
<mx:Text textAlign="left" text="Machine:{omRepeater.getChildAt(0)}" fontWeight="bold" fontSize="16"/>
<mx:ViewStack id="omStack" textAlign="right">
<mx:VBox width="80" height="25" backgroundColor="#FF0000">
<mx:Text text="OMRON SW" fontWeight="bold" color="#000000"/>
</mx:VBox>
<mx:VBox width="80" height="25" backgroundColor="#00FF00">
<mx:Text text="OMRON SW" color="#000000" fontWeight="bold"/>
</mx:VBox>
</mx:ViewStack>
</mx:HBox>
<mx:HBox>
<mx:Text text="Location:{omRepeater.currentItem.retLocation}" fontWeight="bold" fontSize="12"/>
<mx:ViewStack id="osStack">
<mx:VBox width="80" height="25" backgroundColor="#FF0000">
<mx:Text text="SYSTEM SW" color="#000000" fontWeight="bold"/>
</mx:VBox>
<mx:VBox width="80" height="25" backgroundColor="#00FF00">
<mx:Text text="SYSTEM SW" color="#000000" fontWeight="bold"/>
</mx:VBox>
</mx:ViewStack>
</mx:HBox>
</mx:VBox>
<mx:HBox>
<mx:VBox width="125" height="100%">
<mx:Text text="COINS" fontWeight="bold" color="#FEF500" textAlign="center"/>
<mx:Text text="1¢:{omRepeater.currentItem.coinGPercent}" textAlign="center"/>
<mx:Text text="5¢:{omRepeater.currentItem.coinEPercent}" textAlign="center"/>
<mx:Text text="10¢:{omRepeater.currentItem.coinDPercent}" textAlign="center"/>
<mx:Text text="25¢:{omRepeater.currentItem.coinCPercent}" textAlign="center"/>
<mx:Text text="50¢:{omRepeater.currentItem.coinBPercent}" textAlign="center"/>
<mx:Text text="$1:{omRepeater.currentItem.coinAPercent}" textAlign="center"/>
</mx:VBox>
<mx:VBox width="125" height="100%">
<mx:Text text="BILLS" fontWeight="bold" color="#FEF500"/>
<mx:Text text="$1:{omRepeater.currentItem.billDPercent}"/>
<mx:Text text="$5:{omRepeater.currentItem.billCPercent}"/>
<mx:Text text="$10:{omRepeater.currentItem.billBPercent}"/>
<mx:Text text="MULT:{omRepeater.currentItem.billFPercent}"/>
<mx:Text text="MULT:"/>
<mx:Canvas id="multCanvas" width="77" height="12" backgroundColor="#0179E8">
</mx:Canvas>
</mx:VBox>
</mx:HBox>
<mx:HBox>
<mx:Text text="Total: ${omRepeater.currentItem.rettotal}" textAlign="center" fontWeight="bold" fontSize="16" color="#E0EE00"/>
<mx:Label id="lbltime"/>
</mx:HBox>
</mx:VBox>
</mx:Repeater>
</mx:Tile>
</mx:HBox>
<mx:HBox label="RAW DATA">
</mx:HBox>
<mx:HBox label="SETTINGS">
</mx:HBox>
</mx:ViewStack>
</mx:VBox>
</mx:WindowedApplication>