Ouch It hurts when I do that
no text exists for this slide
no notes exist for this slide
A Man Walks into the Doctor
Man: Doctor, it hurts when I do this.
Man: Doctor, it hurts when I do this.
Doctor: Donât Do that. Next!
no notes exist for this slide
Agenda
Introductions
Introductions
Better Mistakes make for Better Developers
Race Conditions
Cross Domain Issues
Performance Problems
Bindings, Bindings, Bindings
If only someone warned me
Summary
no notes exist for this slide
Who Am I
Jeff Tapper (jtapper@digitalprimates.net)
Jeff Tapper (jtapper@digitalprimates.net)
Senior Consultant â Digital Primates
Building Internet Applications since 1995
Authored 11 books on internet technologies
Adobe Certified Instructor for all Flex, AIR, Flash, and ColdFusion courses
http://blogs.digitalprimates.net/jefftapper
Twitter: jefftapper
no notes exist for this slide
Who Are You
Developers who:
Developers who:
Have some experience with Flex
Have a sense of humor
If this isnât you, you should just leave
no notes exist for this slide
Better Mistakes make for Better Developers
There is no silver bullet
There is no silver bullet
Writing good code can be hard
Avoiding common pitfalls helps
no notes exist for this slide
Off to the races
The term Race Condition initially comes from electrical engineering
The term Race Condition initially comes from electrical engineering
A race condition is a flaw in an electronic process whereby the output of the process is unexpectedly and critically dependent on the sequence or timing of other events
The same concept applies to programming
Operations can complete at different times based on outside influences.
no notes exist for this slide
Race Conditions in Flash
Race (or timing) conditions are the single most common type of problem experienced in Flash Development.
Race (or timing) conditions are the single most common type of problem experienced in Flash Development.
We have several tools at our disposal to help avoid Race conditions
Component lifecycle
Events
Bindings
Etc.
no notes exist for this slide
Common Race Condition Scenario 1
Life in a ViewStack
Life in a ViewStack
no notes exist for this slide
Common Race Condition Solution 1
no text exists for this slide
no notes exist for this slide
Common Race Condition Scenario 2
Asynchronous Nature of Component Creation
Asynchronous Nature of Component Creation
no notes exist for this slide
Common Race Condition Solution 2
Lifecycle events â BackgroundLabelFix2
Lifecycle events â BackgroundLabelFix2
no notes exist for this slide
Common Race Condition Scenario 3
Asynchronous Data Access
Asynchronous Data Access
no notes exist for this slide
Common Race Condition Solution 3
DataBinding â lastResult
DataBinding â lastResult
Events â wait for result events
Iâm assuming you already know this part
Complexity is managing when several responses are dependent on each other
no notes exist for this slide
General Rules to avoid Race Conditions
Treat the problem, not the symptom.
Treat the problem, not the symptom.
donât use creationPolicy=âall, â fix the underlying problem
Be aware of the Flex component lifecycle
Understand what happens synchronous vs asynchronously
If itâs not unexpected, its not a race.
no notes exist for this slide
Cross Domain Issues
What are different domains
What are different domains
How do you handle loading data between different domains
crossdomain.xml
Security.loadPolicyFile();
Marshall Plan
Cross SDK Interop
Application Domains
Security Domains
no notes exist for this slide
Whats that about a Marshall Plan
no text exists for this slide
no notes exist for this slide
When do you need allowDomain
If one swf needs to interact with a swf loaded from a different domain
If one swf needs to interact with a swf loaded from a different domain
no notes exist for this slide
Performance Problems
The Flash Player can be a high performance Virtual Machine, if YOU donât screw it up.
The Flash Player can be a high performance Virtual Machine, if YOU donât screw it up.
Have pity on the client (machine)
Understand how and when the screen is drawn.
no notes exist for this slide
Easy to fix problems
Whenever possible, setStyle() before the object is on the display list
Whenever possible, setStyle() before the object is on the display list
private var _submitButton:Button;
protected override function createChildren():void {
_submitButton = new Button();
_submitButton.label = 'Submit';
addChild(_submitButton);
_submitButton.setStyle('backgroundColor', 0x123456);
}
no notes exist for this slide
While we are at it
private var _submitButton:Button;
private var _submitButton:Button;
protected override function createChildren():void{
Super.createChildren()
if (!_submitButton){
_submitButton = new Button();
_submitButton.label = 'Submit';
_submitButton.setStyle('backgroundColor', 0x123456);
addChild(_submitButton);
}
}
no notes exist for this slide
Speaking of setStyle
Avoid calling setStyle() in update display list, unless its actually necessary.
Avoid calling setStyle() in update display list, unless its actually necessary.
No:
_submitButton.setStyle('backgroundColor', currentBackgroundColor);
Yes:
if (_submitButton.getStyle('backgroundColor') != currentBackgroundColor)
_submitButton.setStyle('backgroundColor', currentBackgroundColor);
no notes exist for this slide
Memory Leaks
Stray references will prevent gc
Stray references will prevent gc
Event listeners are the single biggest cause of stray references
Weak References vs removeEventListener
no notes exist for this slide
Bindings Bindings Bindings
Understand how bindings really work
Understand how bindings really work
Binding to functions
Triggering bindings with events
no notes exist for this slide
Listen to the Warnings
Donât ignore the warnings in FB Problems panel
Donât ignore the warnings in FB Problems panel
Strive to have 0 warnings and 0 errors at all times
no notes exist for this slide
Slide 26
Donât be a moron.
Donât be a moron.
Donât use Application.application
FlexGlobals.topLevelApplicaton is just as bad
no notes exist for this slide
Summary
Strive to make better mistakes
Strive to make better mistakes
Steer clear of the races
Be nice to your run time
Watch the leaks
Listen to the warnings
Donât be a moron
no notes exist for this slide
Questions
no notes exist for this slide