This document provides 20 tips for optimizing Flash content, including:
1. Using Flash Player 10.1's built-in optimizations like hardware acceleration.
2. Profiling applications to identify optimization opportunities using tools like FrameStats.
3. Architecting applications using micro-frameworks and lazy loading to reduce memory usage.
6. Tip #4: I/O
•••StrongRTMP.the data with AMF on client and
AMF, lazy loading James Ward’s tool to
Use type Use whenever possible.
server side to increase performance.
benchmark and see the memory difference:
http://www.jamesward.com/census/.
7. Tip #5: Manipulating swf Framerate
• Reducing fps when your app is inactive
• Increase the fps once the app is active again
https://github.com/EladElrom/Flash-Optimizing-Tools
• Increase fps while animation is playing to
framerateManager:FrameRateOptimizer =
create a morenew FrameRateOptimizer(and keeping
smooth experience this, true );
a stack of all the animations being played to
know when we can drop the fps.
• Provide a cross platform API (Pure
AS3, Flex, AIR)
8. Tip #6: Reduce memory usage
Memory leaks due to listeners that have been set by us or
someone else and never removed from memory:
Solution: Listeners API
movieClip.addEventListener( listeners.type =
MouseEvent.CLICK, listeners.handler = onClick );
movieClip.addEventListener( listeners.type =
MouseEvent.DOUBLE_CLICK, listeners.handler = onDoubleClick );
listeners.removeAllListeners( movieClip );
9. Tip #7: Avoid memory leaks
Call gc twice, or in AIR system.gc(): Ensure GC
will do his job correctly:
• Set weekly references - where possible:
addEventListeners and Dictionary classes.
• Don’t keep references - nulling objects with
events don’t unhook them.
10. Tip #8: Update screen
once per frame
Elastic Racetrack
• Frame starts - Event.ENTER_FRAME
• Frame actions executed - Event.FRAME_CONSTRUCTED
• Avoid using updateAfterEvent,
• End of Frame cycle - Event.EXIT_FRAME since it
• Pre-render phasePlayer- and increases the player
interrupt the starts Event.RENDER
• Final user code is executed
work load.
• Player renders changes to display own using the
• Handle invalidation on your
• Cycle completed
stage.invalidate() property
12. Tip #10: Reduce complexity
• Shape level classes such as
• TextField
• Constructor code of children executed: 68
Use low
Constructor code of children executed: 276
Player renders changes display list: possible) over
TextField, SimpleButton (when 168
• mx:Text Spark. It will require more coding but
• haloimprove performance.
Spriteand
will
Constructor code of children executed: 743
• Player renders changes display list: executed: 399
Constructor code of children 685
Avoid using TLF - when possible.
• UIComponent
• s:Label
Use Halo components over Spark components.
Constructor code of children executed: 1136
• Player renders changes display list: executed: 1078
Constructor code of children 198 use Sprite
When creating custom components
over MovieClip and UIComponent over Group
• Group
• s:RichText
• Constructor codegraphics it’s recommended to use
When creating of children executed: 416
Player renders changes display list: executed: 1195
Constructor code of children 3224
Shape display object.
13. Tip #11: Avoid expensive
operations
• Bitmap filters and perspective distortion
• Frequently-updated Text
14. Tip #12: Decreasing execution time
• Primitives vs generic object
if...else statements
•
• Use strict mode
Typing over generic objects
•
• Flex related tips
Loops
• Use e4x with caution
• Array vs ByteArray vs Vector
• Increasing rendering speed
•
• Callbacks andas BitmapData or Bitmap
Manual cache events
•
• Regex as bitmap matrix
Cache and search string
• Databinding
Set all children caching policy
•
• Check the status of all children
Sealed vs. dynamic classes
21. Tip #19: Working with
external assets
• caching data in the memory
• cache data on the local device
• Image blitting
22. #20: be poactive & keep
optimizing
• Be Proactive: take into account benchmark
and memory usage when writing your code.
• Write code first: create your application and
after it’s running, take time to optimize.