Understanding the Get Started Flash Application

In this tutorial, we will build, debug, and deploy the Get Started Flash application, which you saw in the Get Started tutorial.

This tutorial requires Flash Builder 4. So if you do not have it installed, you can download it from http://www.adobe.com/products/flashbuilder/

The Get Started project contains the following:

  • Full source code of the Get Started Flash Application
  • Groovy scripts GSDataItemsandAlarm.groovy and GSGetHistoricalLocations.groovy

How it works

Flash applications communicate with the Axeda Platform through Web Services. This application uses the REST style web services that run a groovy script, called Scripto. This tutorial introduces Scripto. The Flash app presents the platform information in a way that's suited to the audience. This Get Started app is designed to be simple and clean. The code is also meant to be very easy to understand. A full featured application will most likely become more complex.

A Flash app makes a Web Service call that specifies the name of a groovy script. That script runs and produces output. This is often JSON or XML. The Flash app consumes the XML (in this case) and displays in its UI. This app gets an asset's location, data, and alarms. The location is mapped, the data is graphed and the alarms are put into a list.

When your Flash application is ready to be deployed, you can build the released version, zip up the project and upload and host the Application on the Platform.

 

Step 1: Configuring the Groovy Scripts on the Platform

The Get Started application relies on two scripts. You don't see those scripts because they are published as a "root" account. You need to add these 2 scripts so your app can use them and you can modify them.

Right click on the Groovy.zip and save to disk

Navigate to the Configuration Tab

 

Click on New -> Custom Object

 

Enter Name = script Name (eg GSDataItemsandAlarm or GSGetHistoricalLocations)
Type = “Action”
Description = Optional
Source = <paste source code here>
Parameter  =  devicename  (both scripts will jave devicename parameters)
Remember to save the script.
 
You can learn how to test Groovy Scripts on the Platform here

Step 2: Download and Import the Get Started source 

 

1. Right-click the getStarted.zip and save to your hard drive

Open Flash 4 and click on File -> Import Flex Project (FXP)

 

Select File and Browse for the GetStarted.zip file

Click Finish to import the project. The project will be loaded in Flash Builder

 

Step 3: Debugging the Get Started Flash Application

Now you will see how a Flash app calls the Platform. In the code below the function callScripto() takes the name of a groovy script that you created in step 1. The groovy script takes the name of an asset and returns XML containing dataitem values and any alarms for that asset. The function getDataItemsandAlarmsResult() is the handler that's called when the Scripto web service completes. We will see what this looks like.

Open the getStartedApp.mxml and put a breakpoint on line 95 like so:

Debug the Application - when the app starts, you must login with your credentials

Your code will break while the screen loads. Bring up the Flash IDE and select xmlResult, right click and select create
Watch Expression

This will bring up the Expression window which will show you the XML from the Groovy Script (GSDataItemsandAlarm) on the Platform

The following Flash code will populate the DataItem values in a LineChart (lines 99 - 115) 

the values arrayCollection will store the datapoints and the linechart will access them using its dataprovider. 

                for each (var s:XML in xmlResult.History.Value) {
                    
                        if (s != "?" )
                        {
                            lbl_no_data.visible=false
                            values.addItem(s);
                        }
                        else
                        {
   
                        }
                   
                }

                linechart1.dataProvider=values
                ls.setStyle("itemRenderer", new ClassFactory(mx.charts.renderers.CircleItemRenderer));

Please feel free to play around with the code, make changes and hopefully you will be able to easily adapt it to your needs.

Step 4: Uploading the Finished Application to the Platform

When you are familiar with the application, you are ready to upload it to the Platform.

Click on Host an HTML and JavaScript RIA from the Axeda Platform to learn how.

Features in Flash

Here are some ways to easily change the look and feel of your Flash Application in really a few basic steps.

1. In the getStartedApp.mxml, lines 388 and 403
2. Simply change "LineChart" to "BarChart"
3. In line 396, change "LineSeries" to "BarSeries"
Compile and run

Result:

 

 You can easily change the Chart to any of the charts Flash offers.