After a day of reading and many trials and errors I have a successful
event broadcast and listener. A few actually, but the important one is
attempting to save new data from a form activated by the selection of
data grid row.
What I am missing is actually accessing the data behind these events. I
presume I need to do some kind of binding between my components but I am
unclear on what to bind where.
Relevant pieces of my code. Let me know if I need to provide more.
index.mxml [root file]
-----------
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
layout="absolute"
creationComplete="getData()"
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:views="Views.*"
xmlns:Ctrl="Components.Controls.*">
<mx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.utils.ObjectUtil;
.....
[Bindable]
public var troubleLogAry:ArrayCollection = null;
.....
protected function test(e:Event):void
{
Alert.show(e.date.toString());
Alert.show("listener");
}
.....
</mx:Script>
<mx:RemoteObject id="troubleLogDAO" destination="ColdFusion"
source="Model.troubleLogDAO"
result="resultHandler(event)"
fault="faultHandler(event)"
showBusyCursor="true">
<mx:method name="list" result="readLog(event)"/>
<mx:method name="save" result="recordSaved()"/>
</mx:RemoteObject>
.....
<mx:ViewStack id="troubleLog"
width="100%" height="100%"
minWidth="0" minHeight="0">
<views:masterList x="0" y="0" id="master"
gridSource="{troubleLogAry}"
selectTroubleLogView="viewDetails(1)"/>
<views:logDetails x="0" y="0" id="details"
saveTroubleEvent="test(event)"
selectTroubleLogView="viewDetails(0)"/>
</mx:ViewStack>
</mx:Application>
Views/masterList.mxml [Master page with datagrid]
------------------------
<?xml version="1.0" encoding="utf-8"?>
<mx:Panel
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:Ctrl="Components.Controls.*"
layout="absolute"
top="10" left="10" right="10" bottom="10"
title="ITB Trouble Log"
paddingLeft="10" paddingRight="10">
<mx:Metadata>
[Event('selectTroubleLogView')]
</mx:Metadata>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.ListEvent;
import mx.controls.Alert;
import Views.logDetails;
[Bindable]
public var gridSource:ArrayCollection = null;
protected function drillDown(event:ListEvent):void
{
if (event.rowIndex > 0)
{
dispatchEvent( new
Event('selectTroubleLogView'));
}
}
]]>
</mx:Script>
<mx:Label text="Trouble Reports" fontSize="14" fontWeight="bold"
left="10" top="10"/>
<mx:HDividedBox minWidth="0" left="10" top="40" bottom="40" right="10">
<mx:Canvas horizontalScrollPolicy="off" height="100%" minHeight="0">
<mx:DataGrid id="troubleLog"
itemClick="drillDown(event);"
textAlign="center"
dataProvider="{gridSource}" top="0" bottom="0" left="0"
minHeight="0">
<mx:columns>
<mx:Array>
<!--<mx:DataGridColumn dataField="severity"
headerText="Severity" itemRenderer="Components.Renderers.severity"/>
<mx:DataGridColumn dataField="status"
headerText="Status"/>
<mx:DataGridColumn dataField="assigned"
headerText="Assigned To"/>-->
<mx:DataGridColumn dataField="application"
headerText="Application"/>
<!--<mx:DataGridColumn dataField="reported"
headerText="Reported By"/>
<mx:DataGridColumn dataField="description"
headerText="Description" width="300"/>-->
</mx:Array>
</mx:columns>
</mx:DataGrid>
</mx:Canvas>
.....
</mx:HDividedBox>
<mx:Button label="New Item" click="{dispatchEvent (new
Event('selectTroubleLogView'))}" bottom="10" left="10"/>
</mx:Panel>
Views/logDetails.mxml [detail page with form to add|update records]
----------------
<?xml version="1.0" encoding="utf-8"?>
<mx:Panel
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:Ctrl="Components.Controls.*"
layout="absolute"
top="10" left="10" right="10" bottom="10"
title="ITB Trouble Log">
<mx:Metadata>
[Event('saveTroubleEvent')]
[Event('selectTroubleLogView')]
</mx:Metadata>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import Model.troubleLog;
import mx.utils.ObjectUtil;
[Bindable]
protected var troubleEntry:troubleLog = new troubleLog();
protected function save(troubleEvent:Object):void
{
dispatchEvent( new Event('saveTroubleEvent'));
}
]]>
</mx:Script>
<mx:Binding source="te_application.text"
destination="troubleEntry.application"/>
<mx:VBox>
<mx:Form>
<mx:FormItem label="Application">
<mx:TextInput id="te_application"
text="{troubleEntry.application}"/>
</mx:FormItem>
</mx:Form>
<mx:Button label="Submit" click="save(troubleEntry)"/>
</mx:VBox>
<mx:Button label="Trouble Log" right="10" top="10"
click="{dispatchEvent (new Event('selectTroubleLogView'))}"/>
</mx:Panel>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
ColdFusion MX7 by Adobe®
Dyncamically transform webcontent into Adobe PDF with new ColdFusion MX7.
Free Trial. http://www.adobe.com/products/coldfusion?sdid=RVJV
Archive: http://www.houseoffusion.com/groups/Flex/message.cfm/messageid:4315
Subscription: http://www.houseoffusion.com/groups/Flex/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.37