| By Nahuel Foronda, Laura Arguello | Article Rating: |
|
| July 19, 2007 01:30 PM EDT | Reads: |
82,261 |
Adding a Form To Insert Items
Just like you created the TaskItem component, create another one called "EditForm.mxml" that extends the Canvas. In the Design view of this newly created component, add a Textarea with the id "descriptionArea," a ComboBox with the id "priorityList" and a Button. In the Source view, add the priority items to the ComboBox:
<mx:ComboBox id="priorityList">
<mx:dataProvider>
<mx:ArrayCollection>
<mx:source>
<mx:Object label="High" data="1"/>
<mx:Object label="Medium" data="2"/>
<mx:Object label="Low" data="3"/>
</mx:source>
</mx:ArrayCollection>
</mx:dataProvider>
</mx:ComboBox>
Going back to the main application file (mytodolist.mxml), switch to the design view and drag a new panel and inside drag your EditForm component. At this point, your main application should have a list of tasks and a form to add tasks. But the form doesn't send the new task data to the server yet.
Using Events To Communicate Between Components
The goal is that when the user clicks on the "New item" form button, the task data gets sent to the server (see Figure 6). Likewise, when the user clicks on the button on the task item, the task gets marked as done and this information gets recorded in the server. But both of these buttons and forms aren't in the main application where the RemoteObject tag is declared. That means you need a way to make the different components communicate with each other. Flex 2 has a powerful built-in event architecture that you can use to do exactly that.
First you need to make the form button respond to the click event. You'll implement a function called addItem() that will be invoked when the user clicks on the submit button:
<mx:Button label="Add task" id="addButton" click="addItem()"/>
The function must create a new event called saveItemEvent. Store the new task in the event and dispatch it so that other components that might be listening for this event can act on it.
<mx:Script>
<![CDATA[
import mx.events.ItemClickEvent;
public function saveItem():void {
var saveItemEvent:ItemClickEvent = new ItemClickEvent("saveItem", true);
//create a new Task object
var taskData:Task = new Task();
//set its properties using the data entered in the form
taskData.description = descriptionArea.text;
taskData.priority = priorityList.selectedItem.data ;
saveItemEvent.item = taskData;
//announce this event
dispatchEvent(saveItemEvent);
}
]]>
</mx:Script>
Now you must make other components listen to that event. In the main application file, you created a method setUp() that was invoked when the application was completely loaded. In that same method you can specify the main application as a listener to any number of events, including the "saveItem" event your form is dispatching.
addEventListener("addItem",saveTask);
addEventListener("setAsDone",taskDone);
saveTask and taskDone are functions that will be called whenever the application gets notices about the "addItem" and "setAsDone" events.
saveTask simply sends the request to the server by using one of the methods defined in the RemoteObject tag:
private function saveTask(event:ItemClickEvent):void{
var taskItem:Task = event.item as Task;
myRemoteObject.save.send(taskItem);
}
Similarly, the setAsDone function sends a save request, but ensures that the task is set as done before sending the Task object:
private function taskDone(event:ItemClickEvent):void{
var taskItem:task = event.item as task;
taskItem.done = 1;
myRemoteObject.save.send(taskItem);
}
Published July 19, 2007 Reads 82,261
Copyright © 2007 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Nahuel Foronda
Nahuel Foronda is one of the founders of Blue Instant (http://www.blueinstant.com), a web development firm specializing in Rich Internet Applications where he has been creating award-winning applications and offering training for the last five years. He also maintains a blog, called AS Fusion (http://www.asfusion.com), where he writes about Flash, ColdFusion and other web technologies.
More Stories By Laura Arguello
Laura Arguello is one of the founders of Blue Instant (http://www.blueinstant.com), a web development firm specializing in Rich Internet Applications where she has been creating award-winning applications and offering training for the last five years. She also maintains a blog, called AS Fusion (http://www.asfusion.com), where she writes about Flash, ColdFusion and other web technologies.
![]() |
??? 10/30/07 01:47:34 AM EDT | |||
Ipod MP4 ???? |
||||
![]() |
donna 10/12/07 01:28:46 PM EDT | |||
Unable to download the source code. When I got to page http://www.asfusion.com/projects/my-to-do-list/ I received a Coldfusion error: A License exception has occurred. There are so many issues encountered with the tutorial apps out there, that dont work when people follow the isntructions exactly. We need apps that work when followed, and we need downloaded source code that will actually be there. |
||||
![]() |
Lara 07/30/07 11:59:27 AM EDT | |||
I am familiar with ColdFusion but completly new to Flex. I can't get the code to work and I am very frustrated. This isn't a good first application example if we can't work the code. Does anyone have the working source files? If so, please post a link to the corrected files. Thanks! |
||||
![]() |
Jason 06/26/07 02:20:44 PM EDT | |||
I love all the article put out by sys-con and found that they are top quality, that is until this one. I have been struggling with learning Flex and found this article and initally was excited because it looked like the article that was going to clear things up. Until I started in and realized that this article is full of mistakes. Flex is VERY case sensitive where as ColdFusion is not. Since this article is target at ColdFusion developers you need to make sure that the code is correct expecially in the area of case sensitivity because we ususally don't think in that manner (it is "faultString" not "faultstring"). Also you need to make sure that you are using the same name for functions. You have us call the addItem() function through a click event but then on the next page we create the saveItem() function to handle that click event. This won't work! Then we need to make changes to the generated CFCs. You show us the two lines of code that we need to add and simply state that they "should be added to the 'create' method." Ok, but where in the create method. I moved them all over and I continually get errors. I have yet to find a competent article for the Flex "newbie" that achieves its goal of showing how to do basic updates and adds with Flex and CF. I thought that this was going to be the one. Guess I was wrong! |
||||
![]() |
KTK 06/07/07 03:53:09 PM EDT | |||
I'm glad it's not just me! I've had to put this aside for a couple weeks to work on a CF project. Hopefully I can get back to it later this month. If you figure something out, let me know and if I figure it out, I'll let you know. In the meantime, maybe a savior will come along for both of us! |
||||
![]() |
Scott 06/07/07 01:30:06 PM EDT | |||
KTK - I have the same problem and I followed all of the instructions exactly. Uf! |
||||
![]() |
KTK 06/04/07 01:28:59 PM EDT | |||
I'm getting an error that says "A file found in a source-path must have the same package structure '', as the definition's package, 'Task'. I've been beating my head against it for hours and can't figure out why I'm getting the error. Any ideas? |
||||
![]() |
jex 11/04/06 11:26:10 AM EST | |||
OK - I'm a bit new to both Flex and CF, but have been implementing the tutorial fine up until: "Going back to the main application file (mytodolist.mxml), switch to the design view and drag a new panel and inside drag your EditForm component." When I drag the EditForm component onto the panel, nothing happens. Would it be possible to explain exactly what has to be done here? Many thanks. |
||||
![]() |
jex 11/04/06 11:24:25 AM EST | |||
Problem solved - I was trying to drag the EditForm.mxml - but it's the EditForm component(as it says in the tutorial)which needs to be dragged - this is found in the custom component folder. |
||||
![]() |
jex 11/04/06 10:19:33 AM EST | |||
OK - I'm a bit new to both Flex and CF, but have been implementing the tutorial fine up until: "Going back to the main application file (mytodolist.mxml), switch to the design view and drag a new panel and inside drag your EditForm component." When I drag the EditForm component onto the panel, nothing happens. Would it be possible to explain exactly what has to be done here? Many thanks. |
||||
![]() |
Francois-Yanick Bourassa 08/09/06 04:21:30 PM EDT | |||
I found myself a bit confused to follow this article as it is a bit out of the real target - which is bringing new people to use Flex and ColdFusion. As a ColdFusion programmer, I found very interesting to try this example with Flex. But after couple paragraphs, started to be confused on which file I was suppose to put the code as Flex is a real new thing for me - I'm sure it will be the same for few of us - if it is not more! We use to read article where editor just put rectangle on source code by page - but this article seems to have a different goal! I will figure out what was wrong in the code because I think I can but what about newbies!!! This was my personal feedback! |
||||
![]() |
AJAXWorld News Desk 08/09/06 08:35:47 AM EDT | |||
Flex is a complete set of tools to develop rich Internet cross-platform applications based on the Flash platform. With Flex, you can create applications that not only have the 'wow factor' necessary to please clients and users alike, but the 'usability factor' necessary to make your application a real success. |
||||
![]() |
cfdj news desk 08/08/06 08:29:03 PM EDT | |||
Flex is a complete set of tools to develop rich Internet cross-platform applications based on the Flash platform. With Flex, you can create applications that not only have the 'wow factor' necessary to please clients and users alike, but the 'usability factor' necessary to make your application a real success. |
||||
![]() |
CFDJ News Desk 08/08/06 07:25:22 PM EDT | |||
Flex is a complete set of tools to develop rich Internet cross-platform applications based on the Flash platform. With Flex, you can create applications that not only have the 'wow factor' necessary to please clients and users alike, but the 'usability factor' necessary to make your application a real success. |
||||
![]() |
AJAXWorld News Desk 08/08/06 07:11:51 PM EDT | |||
Flex is a complete set of tools to develop rich Internet cross-platform applications based on the Flash platform. With Flex, you can create applications that not only have the 'wow factor' necessary to please clients and users alike, but the 'usability factor' necessary to make your application a real success. |
||||
![]() |
AJAXWorld News Desk 08/07/06 03:11:03 PM EDT | |||
Flex is a complete set of tools to develop rich Internet cross-platform applications based on the Flash platform. With Flex, you can create applications that not only have the 'wow factor' necessary to please clients and users alike, but the 'usability factor' necessary to make your application a real success. |
||||
![]() |
SYS-CON Australia News Desk 08/07/06 09:34:46 AM EDT | |||
Flex is a complete set of tools to develop rich Internet cross-platform applications based on the Flash platform. With Flex, you can create applications that not only have the 'wow factor' necessary to please clients and users alike, but the 'usability factor' necessary to make your application a real success. |
||||
- Kindle 2 vs Nook
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- Confessions of a Ulitzer Addict
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- It's the Java vs. C++ Shootout Revisited!
- Cloud Computing Can Revitalize Your Career as Software Developer
- IBM Could "Reinvent" Java: Mills
- Oracle & Cloud Computing: Exclusive Q&A with SVP Richard Sarwal
- A Brief History of Cloud Computing
- Kindle 2 vs Nook
- Cloud CEOs, CTOs & SVPs to Speak at 4th International Cloud Computing Expo
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- The Difference Between Web Hosting and Cloud Computing
- Cloud Computing Expo: Exclusive Q&A with Yahoo! SVP Cloud Computing
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- My Thoughts on Ulitzer
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- A Cup of AJAX? Nay, Just Regular Java Please
- Java Developer's Journal Exclusive: 2006 "JDJ Editors' Choice" Awards
- The i-Technology Right Stuff
- JavaServer Faces (JSF) vs Struts
- Rich Internet Applications with Adobe Flex 2 and Java
- Java vs C++ "Shootout" Revisited
- Bean-Managed Persistence Using a Proxy List
- Reporting Made Easy with JasperReports and Hibernate
- Creating a Pet Store Application with JavaServer Faces, Spring, and Hibernate
- What's New in Eclipse?
- Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?
- i-Technology Predictions for 2007: Where's It All Headed?










































