Ian what you can do is to have a bindable selectedTroubleInMainApp
:troubleEntry in your main app that will bind to your public
troubleEntry in your detail page (need to change protected to public).
The master page should also contain a selectedTroubleInMaster (public)
which you can bind it directly like this <mx:Binding
source="troubleLog.selectedItem as troubleEntry"
destination="selectedTroubleInMaster"/>
when the master page dispatch a selectTroubleLogView event (for better
reading you should end your events name by Event), in the main app, this
code
selectTroubleLogView='selectedTroubleInMainApp=event.target.selectedTroubleInMaster;'
will assign the new selected value from the grid to the application
selectedTrouble which will be binded to the detail page like this
<views:logDetails x="0" y="0" id="details"
saveTroubleEvent="test(event)"
selectTroubleLogView="viewDetails(0)" troubleEntry="{
selectedTroubleInMainApp }"/>
This should be read like this:
When the datagrid changes the selectedItem, the mx:Binding assigns the
new value to the local variable selectedTroubleInMaster.
The save event dispatches the selection event
the main app gets notified by the new event and executes the script
"selectedTroubleInMainApp=event.target.selectedTroubleInMaster", so
assigns the value of the public variable inside the master to the outer
variable in the main app.
Since that variable is a source of binding, it will propagate to the
detail page. Then you just need to apply the logic to switch views.
Of course the binding can be replaced by some script that will prevent
automatic propagation.
João Fernandes
Ian Skinner wrote:
> 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>
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Upgrade to Adobe ColdFusion MX7
The most significant release in over 10 years. Upgrade & see new features.
http://www.adobe.com/products/coldfusion?sdid=RVJR
Archive: http://www.houseoffusion.com/groups/Flex/message.cfm/messageid:4317
Subscription: http://www.houseoffusion.com/groups/Flex/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.37