Welcome!

You will be redirected in 30 seconds or close now.

ColdFusion Authors: Yakov Fain, Jeremy Geelan, Maureen O'Gara, Nancy Y. Nee, Tad Anderson

Related Topics: Adobe Flex, ColdFusion, Machine Learning

Adobe Flex: Article

Your First Adobe Flex Application with a ColdFusion Backend

The wow factor plus usability

However, the compiler still complains that it can't find the TaskItem component. "But I just created it!" you say. The problem is that the main application doesn't know where to find it. Since you saved it in the same folder, you have to indicate that other components can be found there by adding the following attribute to the Application tag in the mytodolist.mxml file:

xmlns="*"

Lastly, declare the taskData variable in your new component (TaskItem.mxml) so that it will finally compile without errors:

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%">
   <mx:Script>
     <![CDATA[
       [Bindable]
       public var taskData:Task = null;
     ]]>
   </mx:Script>
   <!-- place other code here -->
</mx:Canvas>

Why wouldn't it compile? Because when you put the tag <TaskItem> in the main application, you also specified the attribute: taskData="{taskList.currentItem}." This was necessary to be able to send the current task to the custom component during each loop of the Repeater. This variable has to be set as bindable so that you can bind to its properties in the controls inside this component.

If you look carefully, you'll see that this variable has the type "Task." This type refers to the ActionScript file automatically generated by the ColdFusion wizard. The properties of this class match exactly those of your Task ColdFusion component.

An instance of the TaskItem component (Figure 5) shows the description and priority of the task and a button to remove the task. As described above, the data is set when the component is instantiated by the Repeater and accessible in the variable "taskData" inside the component.

You can use the Design view to drag an Image, a Label, and a Button and put it in the Canvas. The Properties panel of the Design view shows common properties of the selected component. In that panel, set the text property of the Label as: {taskData.description} and the source property of the Image as: images/priority{taskData.priority}.png. Note that you should have a folder called "images" with an image for every priority you want to show. These images should be called "priorityNUMBER.png," where NUMBER should be replaced with the priority number (i.e.: 1, 2, 3).

Everything should compile, but unfortunately you won't be able to see anything because there's no data.

Getting Data from a ColdFusion Service
To load data from a service, you must use a RemoteObject. The simplest way to use a RemoteObject to call a ColdFusion service is by setting its destination to "ColdFusion" and its source to the path to that component. The application will call two methods on the TaskGateway component (generated by the wizard) so you can specify them explicitly inside the RemoteObject tag. When the response from the service comes back, you want a function to be called. The function to call will be different for each method, so you can specify it in the <mx:method> tag with the "result" attribute. Set the result of the method "getAll" to the function "tasksReceived(event)" and the result of the method "save" to the function taskSaved(event)."

<mx:RemoteObject
    id="myRemoteObject"
    destination="ColdFusion"
    source="mytodolist.taskGateway"
    fault="Alert.show(event.fault.faultstring, 'Error');">
    <mx:method name="getAll" result="tasksReceived(event)" />
    <mx:method name="save" result="taskSaved(event)" />
</mx:RemoteObject>

Inside a script block, implement the tasksReceived function as follows to set the source of the task ArrayCollection to what the service sent as a response of the getAll method:

private function tasksReceived(event:ResultEvent):void {
    tasks = new ArrayCollection();
    tasks.source = event.result as Array;
}

If you open TaskGateway.cfc, you'll see that the method "getAll" returns an array of Task objects. When you set that array to the source of the tasks ArrayCollection, the Repeater will get populated with this data since you declared it as the Repeater's dataProvider.

If Flex Builder didn't add the required import statements automatically, add:

import mx.controls.Alert;
import mx.rpc.events.*;
import mx.events.*;

The other function you need to implement is taskSaved. For now leave it empty; you'll complete it later.

private function taskSaved(event:ResultEvent):void {
}

Everything works, but...you still don't see anything on the screen. That's because you haven't called the service yet. Since you want to load the list of tasks as soon as the application loads, put a function call in the applicationComplete attribute of the Application tag. You'll set it to call a custom function called setUp():

applicationComplete="setUp()"

Then implement the function so that it sends the actual request to the server:

private function setUp():void{
    myRemoteObject.getAll.send();
}

Of course you still won't see anything if your database is empty. To test it out, just add a couple of records manually. You'll build the form to enter new items in the next section.

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.

Comments (17)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


IoT & Smart Cities Stories
Every organization is facing their own Digital Transformation as they attempt to stay ahead of the competition, or worse, just keep up. Each new opportunity, whether embracing machine learning, IoT, or a cloud migration, seems to bring new development, deployment, and management models. The results are more diverse and federated computing models than any time in our history.
At CloudEXPO Silicon Valley, June 24-26, 2019, Digital Transformation (DX) is a major focus with expanded DevOpsSUMMIT and FinTechEXPO programs within the DXWorldEXPO agenda. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of business. Only 12% still survive. Similar percentages are found throug...
Japan DX Pavilion at @CloudEXPO Silicon Valley
In his general session at 19th Cloud Expo, Manish Dixit, VP of Product and Engineering at Dice, discussed how Dice leverages data insights and tools to help both tech professionals and recruiters better understand how skills relate to each other and which skills are in high demand using interactive visualizations and salary indicator tools to maximize earning potential. Manish Dixit is VP of Product and Engineering at Dice. As the leader of the Product, Engineering and Data Sciences team at D...
The graph represents a network of 1,329 Twitter users whose recent tweets contained "#DevOps", or who were replied to or mentioned in those tweets, taken from a data set limited to a maximum of 18,000 tweets. The network was obtained from Twitter on Thursday, 10 January 2019 at 23:50 UTC. The tweets in the network were tweeted over the 7-hour, 6-minute period from Thursday, 10 January 2019 at 16:29 UTC to Thursday, 10 January 2019 at 23:36 UTC. Additional tweets that were mentioned in this...
At CloudEXPO Silicon Valley, June 24-26, 2019, Digital Transformation (DX) is a major focus with expanded DevOpsSUMMIT and FinTechEXPO programs within the DXWorldEXPO agenda. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of business. Only 12% still survive. Similar percentages are found throug...
Where many organizations get into trouble, however, is that they try to have a broad and deep knowledge in each of these areas. This is a huge blow to an organization's productivity. By automating or outsourcing some of these pieces, such as databases, infrastructure, and networks, your team can instead focus on development, testing, and deployment. Further, organizations that focus their attention on these areas can eventually move to a test-driven development structure that condenses several l...
The term "digital transformation" (DX) is being used by everyone for just about any company initiative that involves technology, the web, ecommerce, software, or even customer experience. While the term has certainly turned into a buzzword with a lot of hype, the transition to a more connected, digital world is real and comes with real challenges. In his opening keynote, Four Essentials To Become DX Hero Status Now, Jonathan Hoppe, Co-Founder and CTO of Total Uptime Technologies, shared that ...
Over the course of two days, in addition to insightful conversations and presentations delving into the industry's current pressing challenges, there was considerable buzz about digital transformation and how it is enabling global enterprises to accelerate business growth. Blockchain has been a term that people hear but don't quite understand. The most common myths about blockchain include the assumption that it is private, or that there is only one blockchain, and the idea that blockchain is...
Never mind that we might not know what the future holds for cryptocurrencies and how much values will fluctuate or even how the process of mining a coin could cost as much as the value of the coin itself - cryptocurrency mining is a hot industry and shows no signs of slowing down. However, energy consumption to mine cryptocurrency is one of the biggest issues facing this industry. Burning huge amounts of electricity isn't incidental to cryptocurrency, it's basically embedded in the core of "mini...