Transcript Topic Name

AIR: Building Desktop Applications with Flex

Rob Rusher

www.cfunited.com

About Rob Rusher

• • • • • • • Principal Consultant at On3 Former Macromedia Professional Services Working with Flex from the beginning Working with AIR from the beginning Wrote the Adobe Certified AIR course Author of a few ColdFusion books Purveyor of knowledge

www.cfunited.com

2

About this session

• • • What AIR gives you How to create an AIR application with Flex How to implement several AIR features

www.cfunited.com

3

What AIR gives you

• • • • • Runtime (required on the client) • • • Version of Flash Player WebKit SQLite SDK Component Library AIR Developer Tool (ADT) AIR Debug Launcher (ADL)

www.cfunited.com

4

More on the AIR SDK

• • • • • • • • Extension to Flex API File system access Network access Embedded database Drag-n-Drop Windowing Application Update Also a JavaScript version of the API

www.cfunited.com

5

How to Create an AIR Application

www.cfunited.com

6

What did that do?

• • • • • • Application Descriptor Required XML file • Uniquely identifies your application via an Application ID com.on3solutions.myapplication

Version Application Icons Initial window

www.cfunited.com

7

A look at the Application Descriptor

com.on3solutions.feedreader Main Main v1 [This value will be overwritten by Flash Builder in the output app.xml]

www.cfunited.com

8

Lets implement these features

• • • • • File FileStream NativeWindow HTML SQLite

www.cfunited.com

9

File

• • A flash.filesystem.File object • • • represents either a file or directory Some File methods have synchronous and asynchronous versions: • • • –copyTo() and copyToAsync() –deleteFile() and deleteFileAsync() –moveTo() and moveToAsync() Synchronous method calls suspend execution Asynchronous method calls do not suspend code execution, but require an event listener

www.cfunited.com

10

Common directories

www.cfunited.com

11

Files on your system

• • • • Additional methods to open a system dialog with a specified title, and optionally filter by an array of permitted types browseForDirectory( title ) browseForOpen( title, typeFilter ) browseForOpenMultiple( title, typeFilter )

www.cfunited.com

12

Disclaimer

• YOU are the ONLY one responsible for deleting files that shouldn’t be deleted.

www.cfunited.com

13

Deleting files

• • • Methods to recycle or delete a file’s path content deleteFile() deleteDirectory( deleteContent ) } { private function deleteFile( evtObj:Event, tree:FileSystemTree ):void if( tree.selectedItem.isDirectory ) { tree.selectedItem.deleteDirectory(true); } else { tree.selectedItem.deleteFile(); }

www.cfunited.com

14

FileStream

• • • A flash.filesystem.FileStream object is used to read or write files to the file system Again , files may be opened and written synchronous or asynchronous PROGRESS and COMPLETE events are dispatched during read/write

www.cfunited.com

15

Using a FileStream

• • • • • Create a FileStream object Create File objects for the directory and file to read or write Open the file stream for synchronous or asynchronous • • Read or write data to the file stream –readBytes(), readUTF(), readObject(), etc.

–writeBytes(), writeUTF(), writeObject(), etc.

Close the file stream –close()

www.cfunited.com

16

Windowing

• • • NativeWindow mx:WindowedApplication, mx:Window HTMLLoader.createRootWindow, window.open()

www.cfunited.com

17

mx:HTML

• • • • Used to load HTML content within an AS application HTML text provided by the app has full system access Can eval() HTML text loaded from an external URL (including OS files) is loaded with limited security

www.cfunited.com

18

Drag and Drop

• • • • • Supported Types • • • • • Bitmaps Files Text URL Strings Serialized Objects (AMF) Operations Copy Move Link

www.cfunited.com

19

NativeDrag classes

• • • NativeDragManager • NativeDragEvent Clipboard reference • • Clipboard hasFormat() get/set/clearData()

www.cfunited.com

20

Persisting application data

• • • • Embedded SQLite engine Supports AES-CBC 128-bit encryption Stores byte arrays indexed by a string key setItem, getItem, removeItem

www.cfunited.com

21

SQL Classes

• • • SQLConnection SQLStatement Synchronous and Asynchronous methods

www.cfunited.com

22

SQL Syntax

• • • • Parameters :param @param • ?

Numbered params, 0-indexed

www.cfunited.com

23

Updating Applications

• • • • ApplicationUpdater Use version tag in app-descriptor Migration • isFirstRun isNewerVersionFunction

www.cfunited.com

24

Contact Info

On3solutions.com

[email protected]

http://www.robrusher.com

www.cfunited.com

25