www.cfunited.com air: building desktop applications with flex rob rusher

25
www.cfunited.com AIR: Building Desktop AIR: Building Desktop Applications with Applications with Flex Flex Rob Rusher

Upload: ezra-byrd

Post on 02-Jan-2016

215 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Www.cfunited.com AIR: Building Desktop Applications with Flex Rob Rusher

www.cfunited.com

AIR: Building Desktop AIR: Building Desktop Applications with FlexApplications with FlexAIR: Building Desktop AIR: Building Desktop Applications with FlexApplications with Flex

Rob Rusher

Page 2: Www.cfunited.com AIR: Building Desktop Applications with Flex Rob Rusher

2www.cfunited.com

About Rob RusherAbout Rob RusherAbout Rob RusherAbout 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

Page 3: Www.cfunited.com AIR: Building Desktop Applications with Flex Rob Rusher

3www.cfunited.com

About this sessionAbout this sessionAbout this sessionAbout this session

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

Page 4: Www.cfunited.com AIR: Building Desktop Applications with Flex Rob Rusher

4www.cfunited.com

What AIR gives youWhat AIR gives youWhat AIR gives youWhat 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)

Page 5: Www.cfunited.com AIR: Building Desktop Applications with Flex Rob Rusher

5www.cfunited.com

More on the AIR SDKMore on the AIR SDKMore on the AIR SDKMore 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

Page 6: Www.cfunited.com AIR: Building Desktop Applications with Flex Rob Rusher

6www.cfunited.com

How to Create an AIR ApplicationHow to Create an AIR ApplicationHow to Create an AIR ApplicationHow to Create an AIR Application

Page 7: Www.cfunited.com AIR: Building Desktop Applications with Flex Rob Rusher

7www.cfunited.com

What did that do?What did that do?What did that do?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

Page 8: Www.cfunited.com AIR: Building Desktop Applications with Flex Rob Rusher

8www.cfunited.com

A look at the Application DescriptorA look at the Application DescriptorA look at the Application DescriptorA look at the Application Descriptor

<?xml version="1.0" encoding="utf-8" standalone="no"?>

<application xmlns="http://ns.adobe.com/air/application/1.5.1">

<id>com.on3solutions.feedreader</id>

<filename>Main</filename>

<name>Main</name>

<version>v1</version>

<!-- <description></description> -->

<!-- <copyright></copyright> -->

<initialWindow>

<content>[This value will be overwritten by Flash Builder in the output app.xml]</content>

<!-- <title></title> -->

<!-- <systemChrome></systemChrome> -->

<!-- <transparent></transparent> -->

<!-- <visible></visible> -->

<!-- <minimizable></minimizable> -->

<!-- <maximizable></maximizable> -->

<!-- <resizable></resizable> -->

<!-- <width></width> -->

<!-- <height></height> -->

Page 9: Www.cfunited.com AIR: Building Desktop Applications with Flex Rob Rusher

9www.cfunited.com

Lets implement these featuresLets implement these featuresLets implement these featuresLets implement these features

• File• FileStream• NativeWindow• HTML• SQLite

Page 10: Www.cfunited.com AIR: Building Desktop Applications with Flex Rob Rusher

10www.cfunited.com

FileFileFileFile

• 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

Page 11: Www.cfunited.com AIR: Building Desktop Applications with Flex Rob Rusher

11www.cfunited.com

Common directoriesCommon directoriesCommon directoriesCommon directories

Page 12: Www.cfunited.com AIR: Building Desktop Applications with Flex Rob Rusher

12www.cfunited.com

Files on your systemFiles on your systemFiles on your systemFiles 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 )

Page 13: Www.cfunited.com AIR: Building Desktop Applications with Flex Rob Rusher

13www.cfunited.com

DisclaimerDisclaimerDisclaimerDisclaimer

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

Page 14: Www.cfunited.com AIR: Building Desktop Applications with Flex Rob Rusher

14www.cfunited.com

Deleting filesDeleting filesDeleting filesDeleting 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(); }}

Page 15: Www.cfunited.com AIR: Building Desktop Applications with Flex Rob Rusher

15www.cfunited.com

FileStreamFileStreamFileStreamFileStream

• 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

Page 16: Www.cfunited.com AIR: Building Desktop Applications with Flex Rob Rusher

16www.cfunited.com

Using a FileStreamUsing a FileStreamUsing a FileStreamUsing 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()

Page 17: Www.cfunited.com AIR: Building Desktop Applications with Flex Rob Rusher

17www.cfunited.com

WindowingWindowingWindowingWindowing

• NativeWindow• mx:WindowedApplication, mx:Window• HTMLLoader.createRootWindow,

window.open()

Page 18: Www.cfunited.com AIR: Building Desktop Applications with Flex Rob Rusher

18www.cfunited.com

mx:HTMLmx:HTMLmx:HTMLmx: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

Page 19: Www.cfunited.com AIR: Building Desktop Applications with Flex Rob Rusher

19www.cfunited.com

Drag and DropDrag and DropDrag and DropDrag and Drop

• Supported Types• Bitmaps• Files• Text• URL Strings• Serialized Objects (AMF)

• Operations• Copy• Move• Link

Page 20: Www.cfunited.com AIR: Building Desktop Applications with Flex Rob Rusher

20www.cfunited.com

NativeDrag classesNativeDrag classesNativeDrag classesNativeDrag classes

• NativeDragManager• NativeDragEvent

• Clipboard reference• Clipboard

• hasFormat()• get/set/clearData()

Page 21: Www.cfunited.com AIR: Building Desktop Applications with Flex Rob Rusher

21www.cfunited.com

Persisting application dataPersisting application dataPersisting application dataPersisting application data

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

Page 22: Www.cfunited.com AIR: Building Desktop Applications with Flex Rob Rusher

22www.cfunited.com

SQL ClassesSQL ClassesSQL ClassesSQL Classes

• SQLConnection• SQLStatement• Synchronous and Asynchronous methods

Page 23: Www.cfunited.com AIR: Building Desktop Applications with Flex Rob Rusher

23www.cfunited.com

SQL SyntaxSQL SyntaxSQL SyntaxSQL Syntax

• Parameters• :param• @param• ?

• Numbered params, 0-indexed

Page 24: Www.cfunited.com AIR: Building Desktop Applications with Flex Rob Rusher

24www.cfunited.com

Updating ApplicationsUpdating ApplicationsUpdating ApplicationsUpdating Applications

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

• isFirstRun• isNewerVersionFunction

Page 25: Www.cfunited.com AIR: Building Desktop Applications with Flex Rob Rusher

25www.cfunited.com

Contact InfoContact InfoContact InfoContact Info

On3solutions.com

[email protected]

http://www.robrusher.com