www.cfunited.com air: building desktop applications with flex rob rusher
TRANSCRIPT
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
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
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
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)
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
6www.cfunited.com
How to Create an AIR ApplicationHow to Create an AIR ApplicationHow to Create an AIR ApplicationHow to Create an AIR Application
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
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> -->
9www.cfunited.com
Lets implement these featuresLets implement these featuresLets implement these featuresLets implement these features
• File• FileStream• NativeWindow• HTML• SQLite
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
11www.cfunited.com
Common directoriesCommon directoriesCommon directoriesCommon directories
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 )
13www.cfunited.com
DisclaimerDisclaimerDisclaimerDisclaimer
• YOU are the ONLY one responsible for deleting files that shouldn’t be deleted.
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(); }}
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
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()
17www.cfunited.com
WindowingWindowingWindowingWindowing
• NativeWindow• mx:WindowedApplication, mx:Window• HTMLLoader.createRootWindow,
window.open()
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
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
20www.cfunited.com
NativeDrag classesNativeDrag classesNativeDrag classesNativeDrag classes
• NativeDragManager• NativeDragEvent
• Clipboard reference• Clipboard
• hasFormat()• get/set/clearData()
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
22www.cfunited.com
SQL ClassesSQL ClassesSQL ClassesSQL Classes
• SQLConnection• SQLStatement• Synchronous and Asynchronous methods
23www.cfunited.com
SQL SyntaxSQL SyntaxSQL SyntaxSQL Syntax
• Parameters• :param• @param• ?
• Numbered params, 0-indexed
24www.cfunited.com
Updating ApplicationsUpdating ApplicationsUpdating ApplicationsUpdating Applications
• ApplicationUpdater• Use version tag in app-descriptor• Migration
• isFirstRun• isNewerVersionFunction
25www.cfunited.com
Contact InfoContact InfoContact InfoContact Info
On3solutions.com
http://www.robrusher.com