Best practices for mobile development with the Flash Platform
      Mark Doherty | Flash Platform Evangelist




©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
Before starting...




                                                                   3 questions


©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.   2
Why Mark looks so French today?




©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.   3
Ok then... who are you ?




                                                                                Michaël Chaize
                                                                                Flash Platform Evangelist


                                                                                My blog: www.RIAgora.com



                                                                                      @mchaize




©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.   4
Best-practices for mobile development ?




                                                                            “Hopefully everyone understands
                                                                            that Michael Chaize commenting
                                                                               on mobile development is
                                                                               equivalent to Tiger Woods
                                                                            commenting on PaperVision 3D”

                                                                                                  Lee Brimelow




©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.          5
Menu du jour



                                                                                Flash and screens

                                                                                Design considerations

                                                                                Flash best practices

                                                                                Flex on mobile ?

                                                                                AIR on mobile devices

                                                                                Resources


©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.   6
Flash and screens

©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.   7
Applications are beginning adapt to context




                                                                        >           >

                            RIA                                             Cloud       Devices




©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
                                                                                          Adobe Systems Inc.| FOTB2009
Digital Explosion Across Multiple Screens




                                                                                         Consumer
                                                                                         Electronics
                                                                            Mobile
                                                                            Phones


                                                                                          Personal
                                                                                         Computers




©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
                                                                                     9
Flash Platform - A complete system for web innovation




©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
Flash Player 10.1

           e only consistent browser-based runtime for connected devices
    Targeting desktops, mobile phones, netbooks, tablets, and the Digital Home
    On track for delivery to consumers in rst half of 2010
    Runtimes will be available over-the-air through marketplaces and Adobe.com




© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
Flash Player 10.1

    Brings full Flash Player feature set to devices
    New Features:
        Multi-touch & gestures
        Accelerometer
        Screen orientation
        Mobile text input
        Device capabilities discovery
        Globalization support (GSLib)
        Mobile se ings manager
        Global error handling




© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
Flash Player 10.1 API and testing




©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.   13
Design considerations
©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.   14
Context




©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.   15
Screens




                                                                                 800px
                                 480px




                                                                                         480px
                                                         320px




©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.   16
Finger




                                              7mm

                                      44px
                                                                            ≠



©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.       17
Usually, a nger comes with a hand




©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.               18
   Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe con dential.
Native keyboard




©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.   19
Flash best practices
©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
Graphical optimizations




                                                                                    10%




                                                                                          90%




                                                                            rendering     pure algorithm




©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
Understand its behavior




                                                                            Avoid high-rate timers

                                                                            Keep FPS as low as possible

                                                                            Set dynamic FPS
                            FPS and
                           enterFrame
                             events


©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
Memory optimizations and the getSize() method


                      Display Objects                                             Primitive types

    trace(getSize(new Shape()));                                            var a:Number;
    // output: 236                                                          trace(getSize(a));
                                                                            // output: 8

    trace(getSize(new Sprite()));                                           var b:int;
    // output: 412                                                          trace(getSize(b));
                                                                            // output: 4

    trace(getSize(new MovieClip()));                                        var name:String;
    // output: 440                                                          trace(getSize(name));
                                                                            // output: 4

                                                                            name = "";
                                                                            trace(getSize(name));
                                                                            // output: 24


©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
Reusing objects




©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
Freeing memory


 var mySprite:Sprite = new Sprite();

 mySprite = null;

 Remember that when an object is set to null, it is
 not necessarily removed from memory.
 Sometimes the garbage collector does not run, if
 available memory is not considered low enough.
 Garbage collection is not predictable.




                                     Object pooling




©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
Freeing MovieClips



    Text
 Rectangle ? Alpha ? RemoveChild ? Visible ?


runningBoy.addEventListener(Event.ADDED_TO_STAGE,activate);
runningBoy.addEventListener(Event.REMOVED_FROM_STAGE,deactivate);

function activate(e:Event):void
{
  e.currentTarget.addEventListener(Event.ENTER_FRAME,handleMovement);
}

function deactivate(e:Event):void
{
  e.currentTarget.removeEventListener(Event.ENTER_FRAME,handleMovement);
  e.currentTarget.stop();
}



©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
Bitmaps



                Consider bitmaps vs. vectors.

                Avoid filters and blend modes.

                Transparency is very expensive.

                Keep bitmaps as small as possible.

                cacheAsBitmap is not that easy



©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
Text




                    Feel the transparency > opaqueBackground

                    Avoid TLF

                    Test different anti-aliasing technics (lisibility, animation...)

                    Test your animations with different qualities of Stage




©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
Video




                                                H264
©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
Flex on mobile ?
©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
Slider : Flex Mobile Framework



        Flex applications run on Flash Player 10.1, but...
        Challenges: Performance of the SDK, Different screen sizes and densities.
        Based on the Flex 4 codebase, Slider will include signi cant changes to optimize both the
         performance and user experience on more constrained device environments.
        Slider will include new capabilities speci cally designed for mobile development, such as a new
         construct for managing application “screens”. Resolution-independent layout.
        A new set of user interface components will be added which are designed for mobile form
         factors and input methods.




 © 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
31
AIR on mobile devices

©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
Adobe AIR for smartphones (and tablets)


        Adobe AIR allows developers to build standalone applications using Flash technology
        Public support from RIM and Motorola
        First mobile operating system to be supported is Android
        Provides Flash developers access to app stores
        AIR applications can be repackaged for the iPhone




 © 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
33
AIR Packaging & Distribution Work ow



                                                                             .air



                                                                             .exe
                                                      .air
                                              (swf, jpg, mp3)
                                                                             .dmg


                                                                             .ipa


                                                                             .apk

© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
Resources

©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
Resources

                                             ■   Slides and samples on my blog: h p://www.RIAgora.com

                                             ■   Adobe TV

                                             ■   Optimization guides:
                                                 ■   Flash Player optimization for mobile devices
                                                 ■   Optimization for the iPhone
                                                 ■   AIR best practices for mobile devices
                                                 ■   Ads optimization

                                             ■   Technical articles:
                                                 ■   h p://www.adobe.com/devnet/ ashplayer/articles/
                                                     fplayer10.1_hardware_acceleration.html

                                             ■   h p://www. ashmobileblog.com/




©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.          36
Fight !

©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
?
                                                                            Questions

©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
Remember... slide ve...




                                                                            “Hopefully everyone understands
                                                                            that Michael Chaize commenting
                                                                               on mobile development is
                                                                               equivalent to Tiger Woods
                                                                            commenting on PaperVision 3D”

                                                                                                  Lee Brimelow




©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.          39

Best practices for Flash applications on mobile devices

  • 1.
    Best practices formobile development with the Flash Platform Mark Doherty | Flash Platform Evangelist ©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
  • 2.
    Before starting... 3 questions ©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential. 2
  • 3.
    Why Mark looksso French today? ©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential. 3
  • 4.
    Ok then... whoare you ? Michaël Chaize Flash Platform Evangelist My blog: www.RIAgora.com @mchaize ©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential. 4
  • 5.
    Best-practices for mobiledevelopment ? “Hopefully everyone understands that Michael Chaize commenting on mobile development is equivalent to Tiger Woods commenting on PaperVision 3D” Lee Brimelow ©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential. 5
  • 6.
    Menu du jour Flash and screens Design considerations Flash best practices Flex on mobile ? AIR on mobile devices Resources ©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential. 6
  • 7.
    Flash and screens ©2010Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential. 7
  • 8.
    Applications are beginningadapt to context > > RIA Cloud Devices ©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential. Adobe Systems Inc.| FOTB2009
  • 9.
    Digital Explosion AcrossMultiple Screens Consumer Electronics Mobile Phones Personal Computers ©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential. 9
  • 10.
    Flash Platform -A complete system for web innovation ©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
  • 11.
    Flash Player 10.1  e only consistent browser-based runtime for connected devices  Targeting desktops, mobile phones, netbooks, tablets, and the Digital Home  On track for delivery to consumers in rst half of 2010  Runtimes will be available over-the-air through marketplaces and Adobe.com © 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
  • 12.
    Flash Player 10.1  Brings full Flash Player feature set to devices  New Features:  Multi-touch & gestures  Accelerometer  Screen orientation  Mobile text input  Device capabilities discovery  Globalization support (GSLib)  Mobile se ings manager  Global error handling © 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
  • 13.
    Flash Player 10.1API and testing ©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential. 13
  • 14.
    Design considerations ©2010 AdobeSystems Incorporated. All Rights Reserved. Adobe Con dential. 14
  • 15.
    Context ©2010 Adobe SystemsIncorporated. All Rights Reserved. Adobe Con dential. 15
  • 16.
    Screens 800px 480px 480px 320px ©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential. 16
  • 17.
    Finger 7mm 44px ≠ ©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential. 17
  • 18.
    Usually, a ngercomes with a hand ©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential. 18 Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe con dential.
  • 19.
    Native keyboard ©2010 AdobeSystems Incorporated. All Rights Reserved. Adobe Con dential. 19
  • 20.
    Flash best practices ©2010Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
  • 21.
    Graphical optimizations 10% 90% rendering pure algorithm ©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
  • 22.
    Understand its behavior Avoid high-rate timers Keep FPS as low as possible Set dynamic FPS FPS and enterFrame events ©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
  • 23.
    Memory optimizations andthe getSize() method Display Objects Primitive types trace(getSize(new Shape())); var a:Number; // output: 236 trace(getSize(a)); // output: 8 trace(getSize(new Sprite())); var b:int; // output: 412 trace(getSize(b)); // output: 4 trace(getSize(new MovieClip())); var name:String; // output: 440 trace(getSize(name)); // output: 4 name = ""; trace(getSize(name)); // output: 24 ©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
  • 24.
    Reusing objects ©2010 AdobeSystems Incorporated. All Rights Reserved. Adobe Con dential.
  • 25.
    Freeing memory varmySprite:Sprite = new Sprite(); mySprite = null; Remember that when an object is set to null, it is not necessarily removed from memory. Sometimes the garbage collector does not run, if available memory is not considered low enough. Garbage collection is not predictable. Object pooling ©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
  • 26.
    Freeing MovieClips Text Rectangle ? Alpha ? RemoveChild ? Visible ? runningBoy.addEventListener(Event.ADDED_TO_STAGE,activate); runningBoy.addEventListener(Event.REMOVED_FROM_STAGE,deactivate); function activate(e:Event):void { e.currentTarget.addEventListener(Event.ENTER_FRAME,handleMovement); } function deactivate(e:Event):void { e.currentTarget.removeEventListener(Event.ENTER_FRAME,handleMovement); e.currentTarget.stop(); } ©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
  • 27.
    Bitmaps Consider bitmaps vs. vectors. Avoid filters and blend modes. Transparency is very expensive. Keep bitmaps as small as possible. cacheAsBitmap is not that easy ©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
  • 28.
    Text Feel the transparency > opaqueBackground Avoid TLF Test different anti-aliasing technics (lisibility, animation...) Test your animations with different qualities of Stage ©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
  • 29.
    Video H264 ©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
  • 30.
    Flex on mobile? ©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
  • 31.
    Slider : FlexMobile Framework  Flex applications run on Flash Player 10.1, but...  Challenges: Performance of the SDK, Different screen sizes and densities.  Based on the Flex 4 codebase, Slider will include signi cant changes to optimize both the performance and user experience on more constrained device environments.  Slider will include new capabilities speci cally designed for mobile development, such as a new construct for managing application “screens”. Resolution-independent layout.  A new set of user interface components will be added which are designed for mobile form factors and input methods. © 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential. 31
  • 32.
    AIR on mobiledevices ©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
  • 33.
    Adobe AIR forsmartphones (and tablets)  Adobe AIR allows developers to build standalone applications using Flash technology  Public support from RIM and Motorola  First mobile operating system to be supported is Android  Provides Flash developers access to app stores  AIR applications can be repackaged for the iPhone © 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential. 33
  • 34.
    AIR Packaging &Distribution Work ow .air .exe .air (swf, jpg, mp3) .dmg .ipa .apk © 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
  • 35.
    Resources ©2010 Adobe SystemsIncorporated. All Rights Reserved. Adobe Con dential.
  • 36.
    Resources ■ Slides and samples on my blog: h p://www.RIAgora.com ■ Adobe TV ■ Optimization guides: ■ Flash Player optimization for mobile devices ■ Optimization for the iPhone ■ AIR best practices for mobile devices ■ Ads optimization ■ Technical articles: ■ h p://www.adobe.com/devnet/ ashplayer/articles/ fplayer10.1_hardware_acceleration.html ■ h p://www. ashmobileblog.com/ ©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential. 36
  • 37.
    Fight ! ©2010 AdobeSystems Incorporated. All Rights Reserved. Adobe Con dential.
  • 38.
    ? Questions ©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential.
  • 39.
    Remember... slide ve... “Hopefully everyone understands that Michael Chaize commenting on mobile development is equivalent to Tiger Woods commenting on PaperVision 3D” Lee Brimelow ©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con dential. 39