my own little Flex/AS code snippet
Flex2This is a quick snippet of code I figured out using Flex 2.
Background:
I wanted a simple datagrid to show current projects that an end user may have (at my old job, we had what was called a triage view of projects, with levels of importance, etc.)
How this works:
The datagrid, "dg1", gets a list of Projects from my CF Component, named "sourceFlex". The info returned from that CFC goes into the columns as named.
Note: There is a click function listed in the datagrid that sends the selected record to another MXML component that shows record details, etc. I'll post that here shortly.
Also, there is a 'showDate' as function that cleans up how the date looks in the column. (thank you DFW CFUG for that; once I dig up the proper credit for that code from my email archive, I will duly note it.)
In bulleted format, here is the chain of events:
- SWF loads; in the MX:Application tag, I had the "creationComplete" property set to a public function, "initApp()"; inside that function, the remote object method "listP1Projects" from "sourceFlex" (sourceFlex.listP1Projects) is called.
- Call goes to the CFC, and is handled by the "handleP1Projects" method.
- Within that handling method, dg1 has it's dataProvider set to the event's results (dg1.dataProvider = event.result;
- dg1's data columns have their various dataFields set to the proper database columns (ridProject, vcProject, etc)
Code is as follows:
How to get stuff to load at first
MXML Component
MXML Remote Object code (uses a call to a CFC. WAY. EASIER. THAN. WEBSERVICES! Trust me)
AS "handle results" code
AS "showMeFault" code (it's a small "whoopsie" type error with fault event info in an alert popup):
Overall, once you figure out how to 'plugin' your cfc's to send and receive data, getting Flex to play with your DB is way simple.
Caveat: This code ain't the prettiest, it's the result of someone messing with event based coding for the first time. (You do NOT wanna see the AS I cooked up with this entire Flex project. Good. Lord.)





Loading....