![Page 1: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/1.jpg)
Building High Performance iPhone Applications with
Flash CS5
Mike ChambersPrincipal Product ManagerDeveloper RelationsFlash Platform
![Page 2: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/2.jpg)
Adobe Flash CS5 will include support for packaging stand-alone apps for the Apple iPhone
Flash Pro CS5
![Page 3: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/3.jpg)
Smartphone enabled
Multitouch, accelerometer, screen orientation
Optimized memory, power, hardware acceleration
RAW Microphone Access
Global Error Handler
Flash Player 10.1
Public Beta on Labs Now!
Announcement #2 : Flash Player 10.1 - Browser, Desktop (via Adobe AIR 2.0), and smart phones
![Page 4: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/4.jpg)
New APIs• MultiTouch
• Screen Orientation
• MediaLibrary
• Accelerometer
• Geo-location
• Cut / Copy / Paste
• Native TextInput
• tel:, mailto:, maps:, video:
NEW!
Not necessarily iPhone specific APIs.
![Page 5: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/5.jpg)
Flash Player 10.1 will be available across both browsers, desktops and devices. This includes in Adobe AIR 2.0, as well as Flash Player for Palm Pre, Android and Windows Mobile devices.
![Page 6: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/6.jpg)
No Flash Player for Safari Mobile on iPhone
Basically, we need apple’s help with this. However, as the Palm Pre and Android Flash Player demos have shown, Flash content can perform well on this class of devices.
![Page 7: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/7.jpg)
Already a number of iphone applications created with Flash on the itunes app store.
![Page 8: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/8.jpg)
demo
![Page 9: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/9.jpg)
How does it work?
![Page 10: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/10.jpg)
LLVMLow Level Virtual Machine
Open source compiler infrastructure designed for optimizing programs written in arbitrary programming languages
Capable of generating machine code for various targets including x86 and ARM processors
Used in Alchemy
http://www.llvm.org
![Page 11: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/11.jpg)
C
LLVM
x86
C++
SWF / ABC
ARM
Java
...
PPC
Spark
...
Compilation / OptimizationFront End Back End
Adobe built a SWF / ABC front-end for LLVM
![Page 12: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/12.jpg)
SWF
app.xml
app:/resources
PFI
Certificate
.ipa
Flash Pro CS5
PublishDevelop Package Deploy
Publishing workflow
![Page 13: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/13.jpg)
AOT Compilation
• Ahead of Time (AOT) compilation
• iPhone License Restricts interpreters
• Cant JIT code
• No Interpreter
• Compiles ABC bytecode from SWF
• LLVM Base compile toolchain
![Page 14: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/14.jpg)
SWF
app.xml
resources
AOT
.plist gen
.app
info.plist
app:/resources
“swf.exe”
Certificate
.ipaSigned .app
Sign / Package
PFI
ADT input and output
![Page 15: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/15.jpg)
AS3
AS3
SWC
timeline
assets
Flash CS5
ABC1
ABC2
timeline
assets
.swf
ABC Compiler
LLVM Codegen
AOT
LLVM Bytecode
timeline
assets
swf.exe
Flash Runtime Library
ABC1 SHA1
ABC1 SHA2
swf
ARM
Flash Runtime Library
AOT Compilation
AOT Compilation. Notice that there is a library form of the Flash Player runtime included in the application. ABC bytecode is compiled to native arm code.
![Page 16: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/16.jpg)
Developing Content
![Page 17: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/17.jpg)
APIs
Flash Player 10.1 Adobe AIR 2.0
APIs set available is based on Flash Player 10.1 and Adobe AIR 2.0
![Page 18: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/18.jpg)
Flash CS5
.ipa
iTunes
Device
SWF
Desktop
Test Test and Deploy
Development Workflow
![Page 19: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/19.jpg)
In order to deploy an ipa / app to the device, you must be part of the Apple developer program, and have the appropriate certificates and provisioning profiles setup.
![Page 20: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/20.jpg)
Demo
![Page 21: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/21.jpg)
Performance Tips and Tricks
• Most will improve performance / memory usage on desktop
• General ActionScript performance techniques also apply to device
![Page 22: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/22.jpg)
!=
iPhone development is mobile development. It has a significantly slower processor that what you are used to on your desktop.
![Page 23: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/23.jpg)
!=
Screen Size UI Interactions Performance
This affects Screen Size, UI Interactions and most importantly performance. We will focus on performance.
![Page 24: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/24.jpg)
Test and Profile Code
Profile External Application
Profile external SWFs from Flash / Flex Builder. Profile Prospective > Profile > Profile External Application
![Page 25: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/25.jpg)
AS3 Performance Testing Harness
bit.ly/as3performanceGrant Skinner
Make sure to test optimization results.
![Page 26: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/26.jpg)
Debug > Begin Remote Debug Session > ActionScript 3
Remote Device Debugging from Flash CS5
![Page 27: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/27.jpg)
Mac Only
![Page 28: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/28.jpg)
Instruments
Mac Only
![Page 29: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/29.jpg)
Shark
Mac Only
![Page 30: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/30.jpg)
Simple Game Framework
github.com/mikechambers
![Page 31: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/31.jpg)
Rendering
• Hardware Composition is available for DisplayObjects
• Can greatly improve performance
• Uses OpenGL ES-1
• APIs will be available on additional platforms
![Page 32: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/32.jpg)
![Page 33: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/33.jpg)
Software Rendering
Software rendering renders entire display (including composition) via software. CPU intensive.
![Page 34: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/34.jpg)
GPU Compositing
CPU Composition. Individual elements rendered via software, but are then composited / put together in hardware. Can be very fast.
![Page 35: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/35.jpg)
GPU Pipeline with cached surfacesFlash renderer (RAM)
Textures (GPU)
GPU Pipeline with Cached Surfaces
Individual elements can be cached and then composited in hardware.
![Page 36: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/36.jpg)
Using GPU Composition
• cacheAsBitmap:Boolean
• cacheAsBitmapMatrix:Matrix
• Using 2.5D Apis
• Such as setting z property
NEW!
cacheAsSurface new API. Transforms on a display object does not cause it to be re-rendered via software.
![Page 37: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/37.jpg)
![Page 38: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/38.jpg)
cacheAsBitmap
cacheAsBitmap cacheAsBitmapMatrix
• Geometric Translations• Changes in X / Y• Tweens
• Geometric Dilation• Rotation• Scaling
![Page 39: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/39.jpg)
• Can set cacheAsBitmap in IDE or Code
• Have to subclass DisplayObject to set cacheAsBitmapMatrix (can’t set in IDE)
• SGF : CachedSprite.as
![Page 40: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/40.jpg)
Debugging HWA
CTTextureUploadTracking
![Page 41: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/41.jpg)
![Page 42: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/42.jpg)
Use GPU!!!
• Hardware accelerate everything
• Except for items that re-draw often
• Break up display objects to minimize re-draws
• Don’t cache clips that have children that move / change
• Keep display list shallow
![Page 43: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/43.jpg)
Prevent Redraws
• Items moving over non-cached DisplayObjects
• Visual content changes
• Drawing API
• Children moving / changing
• ColorTransformations
• Removing from display list
![Page 44: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/44.jpg)
Minimize Instance Allocations
• Reuse object instances
• Memory Allocation very expensive
• Reduces Garbage collection
• Reduces CPU / Initialization costs
![Page 45: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/45.jpg)
![Page 46: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/46.jpg)
![Page 47: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/47.jpg)
![Page 48: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/48.jpg)
![Page 49: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/49.jpg)
![Page 50: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/50.jpg)
Object Pooling
• Reuses Object instances
• Avoid constant initialization and garbage collection
• Particularly useful for DisplayObjects composited by GPU
![Page 51: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/51.jpg)
Pooling DisplayObjects
• Re-use cached DisplayObjects
• Keep on stage (off screen)
• Can give major performance boosts
• PewPew
![Page 52: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/52.jpg)
GameObjectPool.as
SoundManager.as
![Page 53: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/53.jpg)
Time Management
• In General, ENTER_FRAME performs better than Timer
• Use single listener, and then dispatch
• SGF : TickManager.as
![Page 54: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/54.jpg)
Event Dispatching
• Can be very expensive
• Requires several memory allocations
• Consider using callbacks in CPU intensive areas
• Consider Reusing Event instances
![Page 55: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/55.jpg)
![Page 56: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/56.jpg)
Event Propagation
• Can be very expensive, especially on display list instances.
• Event.stopPropagation();
• Event.stopImmediatePropagation();
![Page 57: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/57.jpg)
![Page 58: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/58.jpg)
Mouse / Touch Events
• Can disable with
• mouseEnabled
• mouseChildren
• Don’t use MouseEvent.MOUSE_MOVE
• Check Mouse position at interval
• Example
![Page 59: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/59.jpg)
Can listen for MOUSE_UP MOUSE_DOWN events to toggle
![Page 60: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/60.jpg)
Thibault Imbert
Optimizing Mobile Content for the Adobe Flash Platform
bytearray.org/?p=1363
![Page 61: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/61.jpg)
Mike Chambers
www.mikechambers.comtwitter.com/mesh
All links at : http://www.mikechambers.com/blog/2009/10/17/resources-for-learning-more-about-flash-to-iphone/
![Page 62: Building High Performance iPhone Applications With Flash](https://reader033.vdocuments.net/reader033/viewer/2022051411/546a510bb4af9fb30d8b48f3/html5/thumbnails/62.jpg)
http://www.flickr.com/photos/bbaunach/1055569383/Baby Crying
Photo credit.