AdvancEDFlashonDevicesMobileDevelopmentwithFlashLiteandFlash10EladElrom,ScottJanousek,ThomasJoosLeadEditorsClayAndres,TomWelshTechnicalReviewerandContributorNancyNicolaisenEditorialBoardClayAndres,SteveAnglin,MarkBeckner,EwanBuckingham,TonyCampbell,GaryCornell,JonathanGennick,MichelleLowman,MatthewMoodie,JeffreyPepper,FrankPohlmann,BenRenow-Clarke,DominicShakeshaft,MattWade,TomWelshSeniorProjectManagerSofiaMarchantCopyEditorHeatherLang,LizWelchAssociateProductionDirectorKariBrooks-CoponySeniorProductionEditorLauraCheuCompositorMollySharp,LynnL'HeureuxProofreaderAprilEddyIndexerBrendaMillerArtistAprilMilneCoverImageDesignerBruceTangInteriorandCoverDesignerKurtKramesManufacturingDirectorTomDebolskiAdvancEDFlashonDevices:MobileDevelopmentwithFlashLiteandFlash10Copyright2009byEladElrom,ScottJanousek,ThomasJoosAllrightsreserved.
Nopartofthisworkmaybereproducedortransmittedinanyformorbyanymeans,electronicormechanical,includingphotocopying,recording,orbyanyinformationstorageorretrievalsystem,withoutthepriorwrittenpermissionofthecopyrightownerandthepublisher.
ISBN-13(pbk):978-1-4302-1904-0ISBN-13(electronic):978-1-4302-1905-7PrintedandboundintheUnitedStatesofAmerica987654321Trademarkednamesmayappearinthisbook.
Ratherthanuseatrademarksymbolwitheveryoccurrenceofatrademarkedname,weusethenamesonlyinaneditorialfashionandtothebenefitofthetrademarkowner,withnointentionofinfringementofthetrademark.
DistributedtothebooktradeworldwidebySpringer-VerlagNewYork,Inc.
,233SpringStreet,6thFloor,NewYork,NY10013.
Phone1-800-SPRINGER,fax201-348-4505,e-mailkn`ano)ju
Forinformationontranslations,pleasecontactApressdirectlyat2855TelegraphAvenue,Suite600,Berkeley,CA94705.
Phone510-549-5930,fax510-549-5939,e-mailejbk<]lnaoo*_ki,orvisitsss*]lnaoo*_ki.
ApressandfriendsofEDbooksmaybepurchasedinbulkforacademic,corporate,orpromotionaluse.
eBookversionsandlicensesarealsoavailableformosttitles.
Formoreinformation,referenceourSpecialBulkSales–eBookLicensingwebpageatdppl6++sss*]lnaoo*_ki+ejbk+^qhgo]hao.
Theinformationinthisbookisdistributedonan"asis"basis,withoutwarranty.
Althougheveryprecautionhasbeentakeninthepreparationofthiswork,neithertheauthor(s)norApressshallhaveanyliabilitytoanypersonorentitywithrespecttoanylossordamagecausedorallegedtobecauseddirectlyorindirectlybytheinformationcontainedinthiswork.
Thesourcecodeforthisbookisfreelyavailabletoreadersatsss*bneaj`okba`*_kiintheDownloadssection.
CreditsIwouldliketodedicatethisbooktomywifeJordana,whomotivated,inspired,andaccommodatedme—whiletak-ingcareofourseventeen-month-oldbabygirl—asIworkedlongnightstocreatethisbook.
IalsowouldliketodedicatethebooktomymotherElenaandbrotherLior;Iamluckytohavetheminmylifeandtoreceivetheirloveandsupport.
—EladElromThisbookisdedicatedtomymotherandfather,whotakeaninterestinmylifeeventhoughtheymightnotalwaysunderstandallthetechnologyandgeekystuff.
Iloveyou.
ThanksalsotomyolderbrothersJeffandPaulforalwaysgivinggood,sound,real-lifeadvicetoayoungersibling.
—ScottJanousekIwouldliketodedicatethisbooktomyparents,whoarealwaysthereforme—whetherI'mplayinginasoccergameorwritinganerdybook.
Thanksforalwaysbelievinginme.
Also,IwouldliketothankmyyoungerbrotherBrecht,whoisdoingagreatjobofbecomingasportsteacher.
Ihopeyoufinishcollegesoon,soyoucangetallthoseyoungpeopleingoodshape.
Iamproudtohaveyoubymyside,togetherwithMomandDad.
Iloveyouall.
—ThomasJoosivForewordxxiAbouttheAuthorsxxiiiAbouttheTechnicalReviewerxxivAbouttheCoverImageDesigner.
xxvAcknowledgmentsxxviIntroduction.
xxviiiPARTONEMOBILEDEVELOPMENTLANDSCAPEChapter1TheMobileandDeviceLandscape3PARTTWOFLASHLITEPLATFORMOVERVIEWChapter2FlashLitePlatformFundamentals29Chapter3FlashLite3101Chapter4TipsandTricksforDevelopingFlash149MobileApplicationsChapter5MobileandDeviceWidgetPlatformswithFlash173Chapter6FlashLiteUserInterfaceComponents241andFrameworksChapter7ExtendingFlashonMobileandDevices279UsingOEM-BasedSolutionsChapter8PortingFlashLiteApplicationstotheiPhone.
315usingThird-PartyToolsCONTENTSATAGLANCEvPARTTHREEAIRAPPLICATIONSFORMULTIPLESCREENSANDMOBILEINTERNETDEVICESChapter9AdobeIntegratedRuntimeonMobileDevices329Chapter10AdoptingAIRforMobileDevices385Chapter11DevelopingCross-PlatformAirApplications431PARTFOURFLEXAPPLICATIONRUNNINGFLASH10ONMOBILEDEVICESChapter12MobileApplicationsandDevelopmentStrategies483withFlex4andFlashCatalystChapter13AdoptingFlexforMultipleDevices525Chapter14BuildingMobileApplicationsUsing561Test-DrivenDevelopmentChapter15CreatingaCross-PlatformVideoPlayer.
619andOptimizingContentIndex699viiForewordxxiAbouttheAuthorsxxiiiAbouttheTechnicalReviewerxxivAbouttheCoverImageDesigner.
xxvAcknowledgmentsxxviIntroduction.
xxviiiPARTONEMOBILEDEVELOPMENTLANDSCAPEChapter1TheMobileandDeviceLandscape3Addressingfragmentation4Gettingtoknowthedevices6Mobilephones6Navigatingthemobilephonedevelopmentecosystem7Preparingforthefutureinthemobileecosystem8MIDandUMPCdevices9Digitalhomeconsumerelectronics10IntegratingFlashontoIntelchips10IntegratingFlashontoBroadcomchips10ARM-baseddevices10Gettingtoknowtheoperatingsystemsandplatforms11Nativelycompiledvs.
interpreteddevelopmentlanguages11UnderstandingtheFlashplatform12WorkingwithFlashLite12ExtendingFlashLite13UsingtheFlashPlayerandAdobeAIRonsmartphones14UnderstandingtheJavaMEplatform14ExploringtherelationshipbetweenJavaMEandFlash16UnderstandingtheSymbianoperatingsystem16ExploringtherelationshipbetweenSymbianandFlash17UnderstandingWindowsMobile17ExploringtherelationshipbetweenWindowsMobileandFlash17UnderstandingtheAdobeMobilePlatform18UnderstandingBREW19CONTENTSCONTENTSviiiExploringtherelationshipbetweenBREWandFlash20UnderstandingtheiPhoneSDK21ExploringtherelationshipbetweentheiPhoneandFlash22UnderstandingtheAOLOpenMobilePlatform22ExploringtherelationshipbetweentheAOLOpenMobilePlatformandFlash23UsingResearchInMotion(RIM)ontheBlackberry23ExploringtherelationshipbetweentheBlackberryandFlash23UnderstandingAndroid23ExploringtherelationshipbetweenAndroidandFlash24UnderstandingPalmPre24ExploringtherelationshipbetweenPalmPreandFlash24Summary25PARTTWOFLASHLITEPLATFORMOVERVIEWChapter2FlashLitePlatformFundamentals29Realizingmultiscreenuserexperiences29GettinguptospeedwithFlashLite30TheFlashplatform31UnderstandingtheimportanceoftheOpenScreenProject32ExploringtheFlashLiteplatform32FlashLitepenetrationstatistics33EvaluatingFlashLiteplayerprosandcons34FlashLiteplayerarchitecture35IntroducingFlashLiteproducts,tools,andservices36AdobeCreativeSuite3and436FlashCS3andCS437DeviceCentralCS437AdobeCaptivateCS4.
37FlashCast.
37FlashHome38AdobeMobileApplicationBuilder38AdobeMobileApplicationPackager39AdobeFlashLite3.
1DistributablePlayer39WorkingwiththeSWFfileformat39PublishingSWFs40DeployingSWFs41ExploringFlashLitecontenttypes42Primarycontenttypes42OEM-specificcontenttypes44LearningthebuildingblocksofFlash-basedcontent46Symbols46TheFlashtimeline47Frames48Layers48Animatingthetimeline49Animatingtext50Workingwithsound50Workingwithvideo51CONTENTSixUnderstandingtheFlashLiteversions53IntroducingtheFlashLiteruntimeversions53ExploringFlashLite1.
154WorkingwithFlashLite1.
1variables,functionclips,andpseudoarrays54Variables54Functionsandfunctionclips55Pseudoarrays55ReviewingFlashLite1.
1ActionScriptsyntax56Globalvariables56MovieClipproperties57Operators59Keywordsandbuilt-infunctions60Usingthefscommand2API65AccessingtheFlashLite1.
1syntaxreferencesheet66KnowingtheFlashLiteerrorcodes67ExploringFlashLite2.
068Handlingtextandfonts68SupportingcompressedSWFformats68IncorporatingXMLsupport69Loadingandplayingbackdynamicmedia69Persistingdata69Playingdevicevideo69AccessingtheDrawingAPI70Usingthefscommand2additions70IntroducingtheFlashLite2.
0errorcodes71ExploringFlashLite2.
172ExploringFlashLite3.
073ExploringFlashLite3.
174ExploringAdobeMobileClient75ExploringActionScript76UsingActionScript1.
076UsingActionScript2.
076ChoosinganActionScript2.
0editor77Developingviathetimelinevs.
classes79Workingwiththetimeline79Usingfunctionsandproceduralcode80Developingclasses81ExploringtheFlashLiteCDKs82IntroducingtheFlashLiteCDKs82IntroducingtheDeviceCentralCS4SDK82IntroducingFlashLitevisualcomponentsets83PackagingFlashLitecontent84UnderstandingFlashLitepackagingformatsforSWFs84PackagingfileformatsandmethodsforFlashLitecontent86CustomSIS86CustomNFL86SWF2SIS86SWF2GoProfessional87SWF2JAR87Jarpa88CONTENTSxSWFPack.
com88ForumNokiaFlash(andFlashLite)packager89SWF2NFL89AdobeMobilePackager89W'd-get-it91DistributingandmonetizingFlashLitecontent92IntroducingFlashLitecontentaggregatorsandproviders93Zed93ThumbPlay93GetJar93NokiaMOSH94NokiaSoftwareMarketandNokiaDownload!
94VerizonWirelessGetItNow95Smashingcontent95ShockwaveGames(AtomEntertainment)95MoketContentNetwork95Handango95Voeveo96Mobibase96ClickGamer96FunMobility96ChumbyNetworkportal96IguanaMobile97AggregatingcontentforFlash10andAIRapplications97Distributingviadirect-to-customerandconsultationmodels97IntroducingtheOpenScreenProjectFund97JoiningFlashmobileanddevicedevelopmentcommunities98Summary99Chapter3FlashLite3101GettingtoknowFlashLite3.
0102Improvingperformance102Enhancingvideocapabilities103Browsingwebcontent103Localfilesecurity105Managingcontent106GettingtoknowFlashLite3.
1110Enhancingmobileanddevicewebbrowsing110SupportingFlash9(ActionScript2only)110UsingtheLocalConnectionclass111EnhancingHTMLbrowsersupport115UsingthenewHTMLcapabilities117Videoenhancements121MP3streamingsupport122GraphicAPIadditions122ActionScriptenhancements123WorkingwithFlashLite3.
x124Explainingmash-ups125CreatingourFlashLite3videoapplication125CONTENTSxiExploringtheAdobeDistributablePlayerSolution139DownloadingtheFlashLite3.
1DistributablePlayer140UsingAdobeMobilePackager140DownloadingAdobeMobilePackager141AccessingAdobeMobilePackagerdocumentation142AccessingtheFlashLiteDistributablePlayertutorials142IntroducingtheAdobeDeviceCentralCS4SDK143DownloadingtheAdobeDeviceCentralSDK144ExploringtheAdobeDeviceCentralSDK144Installingsampleplug-ins145LeveragingAdobeDeviceCentralCS4plug-ins145Summary146Chapter4TipsandTricksforDeveloping149FlashMobileApplicationsOptimizingyourmobileuserinterface149Keepingitsimple150Visualizinginteraction150Usingsoftkeylabels151Usingarrowvisualization151Highlightingitems151Minimizinginteractionpossibilities151Providingextraexplanation152Minimizingtext152Consideringusability:fourreasonsusercontextisimportant152Light152Time153Applicationawareness153Movement153Optimizingformobiledevices154Managingmemory154Understandingthestaticanddynamicmemoryheaps154Understandingthegarbagecollector154Optimizingforefficientmemoryuse156ImprovingCPUperformance157Renderingbitmapartwork158LoadingXMLdata158UsinggotoAndPlay(158Tweeningobjects158Registeringvariablesanddefiningfunctions158Loopingiterations159Usingevents159Optimizingcalculations159Optimizingaprojectbeforepublishingit159UsingOxygen,theFlashLiteDevelopersKit160Testingusingmobileemulators160AdobeDeviceCentral160Usingdeviceprofiles161Previewingapplicationappearanceandperformance161CONTENTSxiiDeviceAnywhere162Emulatingallmajorworldwidecarriersandtheirnetworks162Previewingapplicationappearance162Workingthroughbestpracticestutorials162Usingpersistentdata162Configuringtheapplication162Checkingexistingdata163LoadinginteractiveSWFfiles164UsinglocalandexternalSWFfiles164LoadingexternalfilestostreamvideoinFlashLite3168Summary170Chapter5MobileandDeviceWidgetPlatformswithFlash173Understandingwidgets174Runningwidgetsonthedesktop174Runningwidgetsonmobileanddevices174DevelopingwidgetswithNokiaWebRuntime175LearningthebasicsofWRT176PreparingtodevelopawidgetforanS60device177Exploringthewidgetfiles178Exploringtheinfo.
plistconfigurationfile181BuildingaFlashLite–basedWRTwidgetusingAptanaStudio182Downloading,installing,andconfiguringAptanaStudio184DownloadingandinstallingtheNokiaWRTplug-in185DevelopingaNokiaWRTwidget187DesigningtheNokiaWRTwidget'sFlashLitecontent191AddingtheFlashLitecontenttoaNokiaWRTwidgetframework194PackagingaNokiaWRTwidget195PackagingFlashLitecontentinawidget196TestingaWRTwidget197TestingwiththeNokiaS60platformSDKemulator197TestingwithNokiaS60handsets198TestingwithAptana199TestingwithRDA200TestingwithAdobeDeviceCentral201DeployinganddistributingWRTwidgets201MOSH201TheOVIStore202NokiaDownload!
202Otherdistributionmethods202InstallingawidgetontoasupportedS60device202DevelopingChumbywidgets203IntroducingtheChumby204Understandingglanceabletechnology204ComparingChumbyandNokiaWRTwidgets204HackingtheChumby206Accessingonlinecommunitysupportresources207GettingholdofaChumby207ExploringtheChumby208CONTENTSxiiiGettingreadyforChumbywidgetdevelopment209FlashwidgetsontheChumby209Deliveringcontentviachannels209UnderstandingChumbyinputmethodsandsensorAPIs210Touchscreen211Accelerometer211Bendswitch212Microphone212Display212UsingChumbyvariables212Widgetparameters213Widgetconfigurationvariables213UsingtheChumbyfscommand2API213DealingwithFlashsecurityontheChumby215Workingwithaudio216Workingwithvideo216Loadingandsavingdata217Remotedata217Persistentdata217Workingwithwidgetconfigurators217PublishingChumbySWFs218Findingtips,tricks,andfurtherresourcesforChumbywidgets219UsingbestpracticesforChumbywidgetdevelopment219BuildingaFlashLitewidgetfortheChumby219DownloadingandinstallingSWFMill220DownloadingandinstallingFlashDevelop221CreatingtheAssetSWF223DevelopingtheFlashLiteChumbywidget224TestingChumbywidgets230TestingwithouttheChumbydevice230TestingontheChumbydevice232DeployingawidgetontheChumbyNetwork234MonetizingChumbyplatformdevelopment238Summary239Chapter6FlashLiteUserInterfaceComponents241andFrameworksFlashLiteuserinterfaces242BenefitsofFlashLitewithuserinterfaces242LeveragingFlashLiteuserinterfaces243On-deviceuserinterfaces243UserinterfacesinFlashLiteapplications244CreatingFlashLiteuserinterfaceswithcomponentsandframeworks244FlashLiteFeatherFramework245DownloadingandexploringtheFeatherFramework245ExaminingtheLitedaysdemoapplication246DownloadingandexploringFeatheruserinterfacecomponents260FlashLiteBlocketPCLayoutManager261FeaturesoftheLayoutManager262CONTENTSxivExploringtheLayoutManagerdemos262ExploringtheLayoutManagerdemo01.
rarexample263ShurikenFlashLite2.
xcomponentframework264DownloadingandinstallingShuriken265ExploringtheShurikencomponents266OxygenToolkit(forNokiadevices)268ExploringtheOxygencomponents268DownloadingandinstallingtheOxygenToolkit269UsingtheOxygencomponents270NokiaFlashLiteIndicatorandListcomponents271ExploringtheNokiaFlashLite2.
xcomponents271DownloadingandinstallingtheNokiaFlashLite2.
xcomponents272UsingtheNokiacomponents273ForumNokiaFlashLitecomponentset274ExploringtheNokiaFlashLitecomponentset274DownloadingandinstallingtheNokiaFlashLitecomponentset274UsingtheNokiaFlashLitecomponentset275AdobeXDFlashLiteuserinterfacecomponentexamples275ExploringtheAdobeXDFlashLiteuserinterfacecomponents275DownloadingtheFlashLiteuserinterfacecomponents277UsingtheFlashLiteuserinterfacecomponents277Summary277Chapter7ExtendingFlashonMobileandDevices279UsingOEM-BasedSolutionsWorkingwithnext-generationmobileanddeviceAPIs280ExtendingFlashLitewithdeviceAPIs280PoweringFlashwithNokiaS60PlatformServices281IntroducingS60PlatformServices281GettingtoknowtheS60PlatformServicesmethods282LeveragingS60PlatformServices284InstallingtheNokiaS60PlatformServiceAPIs284TargetingS60PlatformServices–supporteddevices285WritinganinlineSMSapplication286GettingmoreinformationonS60PlatformServices289ExtendingFlashonSonyEricssondevices290GettingstartedwithFlashonSonyEricssondevices290WorkingwithaccelerometersonSonyEricssondevices291Detectingdevices291Accessingtheaccelerometer292IntroducingProjectCapuchin294Lookingathigh-levelProjectCapuchinarchitecture296ExploringtheusecasesforProjectCapuchin297PassingdatabetweenJavaandFlashLite297UsingDataRequest298UsingExtendedEvents299CONTENTSxvSettingupthedevelopmentenvironmentforProjectCapuchin300CreatingyourfirstProjectCapuchinapplication301Downloading,extracting,andinstallingtheProjectCapuchinexample301WalkingthroughtheJavaMIDlet303WalkingthroughtheFlashLiteuserinterface306PackagingFlashLitecontentwithSWF2JAR307GettingmoreinformationaboutProjectCapuchin311ExtendingActionScriptinFlashLite3.
1311LookingforwardtoFlash10andDeviceAPIs311Summary312Chapter8PortingFlashLiteApplicationstotheiPhone.
315UsingThird-PartyToolsPortingFlashapplicationstotheiPhoneusingb.
Tween316IntroducingeyeGT316UnderstandingtheinnerworkingsofeyeGT317ConvertingFlashapplicationsintonativeiPhoneapplications319GettingtoknowtheMonsterMatchgame319Changingtheinterface319UsingthereAnimatortool320PortingtotheiPhone322Emulatingtherootobject322Gettingreadytodeploy323Flashontouch-screendevices323Touchingthings323Designingatouch-basedUI324Summary324PARTTHREEAIRAPPLICATIONSFORMULTIPLESCREENSANDMOBILEINTERNETDEVICESChapter9AdobeIntegratedRuntimeonMobileDevices329Takingahigh-levelviewoftheAIR1.
5platform330UsingtipsandtricksforFlashPlayer10onmobiledevices333Movingobjectsin3-Dspace334UsingPixelBenderforgraphicsandcalculations337CreatingcustomfilterswithPixelBender337UsingPixelBendertocalculateinformation340UtilizingtheTextLayoutFramework348UsingtheSparkTextArea352Creatingsounddynamically357Improvingvisualperformance359UsingtheenhancedDrawingAPI362Readingandwritinglocalfiles363CONTENTSxviTakingahigh-levelviewofAIR1.
5capabilities368LoadingHTMLandJavaScripttoacontainer368Accessingthelocalfilesystem370EncryptingSQLitedata372UpdatingapplicationsandusingthenotificationAPI375Listeningtonetworkchanges375Changingnativewindowingandchromecontrol377SigningyourAIRapplication379Choosingyourdigitalsigningmethod379SigningyourapplicationwithFlexBuilder380Summary382Chapter10AdoptingAIRforMobileDevices385Implementingplatformandcontextawareness386Detectingsystemcapabilities387Detectingsystemsupport389Detectinguserpresence391Detectingnetworkconnectivitychanges392DetectingHTTPconnectivity392Detectingsocketconnectivity393Detectinglocaldrives393Detectingapplicationwindowmovement394GettingtheAIRruntimeversionandpatchlevel394Adaptingconfigurationandbehavior398Downloadingfilesfromaserver399ImplementingHTTPconnectivityawareness401Usingadatabasetostoreinformation401CreatingaSQLitemanager402Mobiletouchandmultitouchscreenapplications413Understandingthetouchscreen413CreatingaUMPCtouchscreenapplication415Creatingaseamlessinstallationexperience421Enablingbrowserinvocation423Creatingacustombadgeinstaller424InstallingtheBrowserAPI426Summary429Chapter11DevelopingCross-PlatformAirApplications431IntroducingthebasicsofdynamicGUIs432UnderstandingthePassiveMulti-viewdesignpattern433UnderstandingthePassiveViewdesignpattern435UnderstandingtheFactorydesignpattern436Puttingthepatternstogether436ImplementingthePassiveMulti-viewdesignpattern437Creatingtheabstractpassivemainviewclass438Creatingthepassivemainviewclass438Creatingtheabstractpassivesubview439Creatingthepassivesubview439CONTENTSxviiCreatingthefactoryclass440Creatingthepresenterclass441Creatingthecreatorclass442Developingthemusicplayerapplication444BuildingthemusicplayerAPI444CreatingtheIPlayerinterface444CreatingtheAbstractPlayerclass445CreatingthePlayersubclass449CreatingthemusicplayerGUI455CreatingGenericMusicPlayer.
mxml455CreatingaGUIforamusicplayerapplication459Creatingtheloginform459CreatingtheGUI462Creatingthecreatorclass464Creatingtheskincomponents466ImplementingtheAbstractMusicPlayerMainclass472ImplementingtheAbstractMusicPlayerclass473Makingtheapplicationcontextawareandadaptable476Utilizingcontextawarenessformultipleviews476Adaptingtheapplication477Summary478PARTFOURFLEXAPPLICATIONRUNNINGFLASH10ONMOBILEDEVICESChapter12MobileApplicationsandDevelopmentStrategies483withFlex4andFlashCatalystGettingtoknowFlashCatalyst483ExploringthebenefitsofCatalyst484Gettingthetool484SeparatingpresentationfromlogicwithFlashCatalyst484ExploringFlash'snewdevelopmentcycle485GettingstartedwithFlashCatalyst486CreatinganewCatalystproject487CreatingyourfirstfullCatalystapplication489Creatinggraphics489Convertinggraphicstocomponents491Choreographingtheapplication492Addingactionstothebuttonswecreated493Switchingtocodemode493CreatinganapplicationwithFlashCatalystandFlexBuilder496Refactoringthecode497Addingtheuserauthenticationservice497Addingincorrectcredentialandloggedinstates500CreatingamobileapplicationwithCatalystandAIR501CreatingtheFlashCatalystproject502Convertinggraphicstocomponents504CONTENTSxviiiAddingFXGgraphicelements505Addingbuttonstateinteractivity506Creatingthedetailstate507Addinginteractivitybetweenstates508ImportingtheFXPprojectintoFlexBuilder4509ConvertingtheprojecttoanAdobeAIRproject511GettingthelistofYouTubevideos512GettingYouTubefeedswithourutilityclass512ExtractingtheFLVfromtheYouTubeutilityclass514AddinglogictotheFlashCatalystapplication516SigningyourAIRapplication519SigningyourapplicationwithFlexBuilder520DeployingyourAIRapplicationonaUMPC522Summary523Chapter13AdoptingFlexforMultipleDevices525CreatingaFlexGUIfortheNokiaN810browser526CreatingdynamicGUIsusingFlashCatalyst527CreatingaGUIfora320480-pixelscreenwithCatalyst528ImportingtheIllustratorfileintoCatalyst528ImportingartworkintoFlashCatalyst529ConvertinggraphiccomponentstoFlexcomponents530ConvertingtheslidergraphicintoMXMLcomponents532CreatingaGUIfora530520-pixelscreenwithCatalyst533ConvertinggraphiccomponentstoFlexcomponents534ConvertingslidersgraphicsintoMXMLcomponents535ImportingFlashCatalystGUIsintoFlex4SDK536ImportingtheFXPproject537ImplementingthePassiveMultiviewdesignpattern537CreatinglogicforFlashCatalystapplications541Creatingthemainview,MusicPlayerMain.
mxml542CreatingthesubviewsforMusicPlayer.
mxml544SkinningtheFlexcomponents552Summary559Chapter14BuildingMobileApplicationsUsingTest-Driven.
561DevelopmentUnderstandingTDDbasics562CreatingunittestsusingFlexUnit563Creatingyourfirsttestsuiteandtestcase564CreatingtheTestSuiteclass564CreatingtheTestCaseclass564CreatetheTestRunnercomponent565Writingafailedunittest566Writingcodetopassthetest567CONTENTSxixPassingthetest568Refactoringthetest'scode568Repeatingthisprocess569Usingassertionmethods570FlexUnitinFlex4571CreatingatestsuiteandtestcaseinFlex4572Creatingatestsuiteclass572Addingatestcaseclass573Writingafailedunittest575Writingcode578Passingtheunittestassertion579Refactoringourcode579Creatingasecondunittest579Writingasynchronoustests581TestingvisualcomponentswithFlexUnit586TDDwithMVCframeworks590UsingTDDwithCairngorm591Creatingtheusecase591Creatingtheapplicationmodel592CreatingtheMain.
mxmlclass595Creatinginitializationevents598CreatingtheAdobefeedscontainer599Addingtheservicecall602Respondingtouserselectionsofafeed604Creatingtheapplicationtestsuiteandtestcases605UsingTDDwithPureMVC609Creatingthemediatorclass610Creatingtheproxyclass612CreatingthetestsuiteandtestcasetotestPureMVC614Summary616Chapter15CreatingaCross-PlatformVideoPlayer.
619andOptimizingContentInitialstrategychoices:reusingorcreatingvideocontent621Tipsformakinggreatmobiledevicevideocontent622VideoCodec411625PlaybackusingdeviceandFlashvideo626FLV,themostpopularsupportedvideoformat628F4Vformat628H.
264format6283GPformat628Dynamicallydiscoveringadevice'savailablecodecs629DetectingdevicecapabilitiesinFlashLite629EncodingvideoforFlashapplications631CompressingvideofilesusingtheAdobeMediaEncoder631Understandingthedifferencebetweenstreamingandprogressivedownload637Tipsforselectingserversforyourvideos638CONTENTSxxBuildingaprogressivedownloadvideoplayerformobiledevices639CreatingvideoplaybackcomponentsinFlashProfessional639CreatingavideoplayerinFlashLite642CreatingavideoplayerforFlash10646VideoDisplayforFlash10652Detectingconnectionstatus656Astreamingandoptimizingtechniqueformobiledevices658FMSarchitectureoverview658InstallingFMS3.
5onWindows659StreamingvideotoamobiledeviceusingFMS3.
5662Settingasmartbufferpolicy665BandwidthDetection666Dynamicallyswitchingbetweendifferentvideoprofiles676FMS3.
5DVRusingFlashMediaLiveEncoder3.
0677Embeddingvideotechniques677EmbeddingavideofileinaFlashLiteapplication677EmbeddingavideofileinFlash10679AdobeStrobeandOpenVideoPlayer(OVP)initiatives680Dynamicswitchingofvideoprofiles680Enhancingprogressivedownloadseeking688AdobeStrobeframework688Summary697Index699xxiThetechnologylandscapehasneverbeenmoreexciting,andithasalsoneverbeenmorecon-fusing.
Everywhereyoulook,youseeanumberofwaystoconnecttoyourfriendsandconsumedigitalcontent.
Mobiledevices,yourlivingroomconsumerelectronicdevices,PCs,laptops,andnetbooksareallincreasinglyconnectedandcapableofprovidingafullwebexperience.
AllofthisisverygoodnewsforFlashdevelopers.
FlashcontinuestoletdevelopersanddesignerscreaterichInternetapplicationsacrossmultiplescreens.
AtAdobe,wehavebeenworkingveryhardonthenextgenerationoftheFlashPlayerformobiledevicesaswellasforcutting-edgeareas,likethedigitallivingroom.
OneofthecorepromisesoftheFlashPlayerhasalwaysbeentoprovideaconsistentexperi-encefortheuserregardlessoftheoperatingsystemorthebrowser.
Inaworldwherenotonlytheoperatingsystemsbutthehardwareandscreensizesarealldifferent,thatpromiseisevenmoreimportant.
Youhavetobeabletoreachyourcustomersonwhateverdevicethey'reusing,whilestillprovidingtherichuserexperiencethatusersnowexpect.
ThereisnobetterormoreefficientplatformforcreatingrichcontentthatwillruneverywherethanFlash.
Upuntilnow,therehasn'tbeenabookthatcoversthewiderangeoftheFlashplatform,sothisbookissorelyneeded.
ThebreadthoftheplatformmeansthatFlashdevelopersareundermoreandmorepressuretodeliveracrossallmultipleenvironments.
ThefactthatFlashaccountsforover85percentofvideostreamedontheWebmeansthatthetraditionalFlashworldiscollid-ingwithothermedia,andtheskilldemandsonaFlashdeveloperhaveneverbeenmorediverse.
Partdesigner,partdeveloper,andpartrich-mediaguru,theFlashdeveloperneedstohavemanytoolsavailable.
Thisbookdoesagreatjobofcoveringthebuddingmobilespace,thebrowserspace,andthedesktopspaceallthewhileprovidingtipsandtrickstousethetoolsandtech-nologiesoftheFlashplatform.
Thisbookcouldn'thaveastrongersetofauthors.
EladElromisarisingstaroftheFlashdevel-opmentworld.
Hebringsafreshperspective,astrongbackground,andaninherentknackforthemoresubtleaspectsoftheFlashplatform.
He'sbeeninvolvedveryearlyinanumberofAdobeproducts,providingfeedbackandideastoensurethattheplatformremainscuttingedge.
ScottJanousekneedsnointroductioninmostFlashcircles.
HecameearlytotheworldofFlashmobileandhaswatcheditgothroughmany,manyiterations.
HehasbuiltsomeofthemostcompellingFlashLitedemonstrationsoutthereandhasbeenaconstantresourceforthecommunitywhenitcomestoFlashonmobiledevices.
Havinghimauthorabooklikethis,atatimewhenFlashonmobiledeviceshasneverbeenmoreexciting,isaresoundingendorsementofbothwhat'sinsideandwhat'scomingforFlashdevelopers.
FOREWORDxxiiFOREWORDThemultiscreenexperiencebringsmanychallengesandmanyopportunities.
AsaFlashdevel-oper,you'vegotalegupontherestofyourcompetition.
Thecombinationofgreattools,greatservices,andaformidablerichmediainfrastructuremeansyoucantargetthesedeviceswithnext-generationuserinterfacesandmedia.
ThisbookwillbeagreatresourceasyounavigatethewatersofmultiscreenandmobiledevelopmentwiththeFlashplatform.
RyanStewartxxiiiEladElromisatechnicalwriter,technicallead,andseniorFlashengineer.
Asatechnicalwriter,EladwrotebookscoveringFlashtechnologies.
Hemaintainsanactiveblog(dppl6++sss*ahnki`aoecj*_ki+^hkc)andhasspokenatseveralconferencesregardingtheFlashplat-form.
HehashelpedcompaniesfollowtheXPandScrummethodologiestoimplementpopularframeworks,optimizeandautomatebuiltprocessorsandcodereview,andfollowbestprac-tices.
Eladhasconsultedforavarietyofclientsindifferentfieldsandsizes,fromlargecorpora-tionssuchasViacom,NBCUniversal,andWeightWatcherstostartupssuchasMotionBox.
comandKickApps.
com.
ScottJanousekisatechnicalwriter,softwaredeveloper,traininginstructor,communityevange-list,worldwidespeaker,andCEO.
HeisalsotheownerofHookenMobile,amobiledesignanddevelopmentcompanybasedintheUnitedStates,inthesuburbsofBoston,Massachusetts.
ScottisanAdobeCertifiedFlashDesignerandDeveloperaswellasarecognizedFlashmobileexpert.
InadditiontoworkingwithFlashMobile,heisalsocurrentlycreatingnativeapplicationsfortheiPhone,webOS,andAndroidplatforms.
AsanactiveandcontributingmemberoftheAdobeFlashMobileUserGroup,BostonFlashPlatformUserGroup,MassMobile,andMobileMondayBoston(momoBoston),ScottispassionateaboutmobileanddevicesandworkswiththeFlashplatformacrossallsortsofdevicesandgadgets.
FormoreinformationaboutScottandhislatestmobileanddeviceendeavors,checkouthispersonalblogatdppl6++sss*o_kp)pf]jkqoag*_ki+^hkc+.
ThomasJoosisamobileconsultantwhograduatedwithadegreeinmultimediaandcom-municationtechnologyfromtheTechnicalUniversityWest–Flanders.
Asaresultofhispassionformobile,ThomasspecializedinFlashLitedevelopmentandmobileconceptsanddesign.
InDecember2008,hewonanAdobeMaxAwardforRockWerchterMobile,theonlymobileentrythatmadeitintotheEuropeanfinals.
Thomasisalwaysonthelookoutforanymobileopportunitiesthatcouldaddvaluetoaclient'sonlinecampaign,experience,orcommunica-tionplatform.
Fueledbyhisinterestinmobiledesignandconcepts,combinedwithastrongtechnicalknowledgeinFlashLite,Thomasoffersawidevarietyofmobileconsultation,fromtechnicaltrainingsessionsandworkshopstobrainstormingmeetings,andhe'sconstantlylookingformobileplatformopportunitiesforclientsandtheironlinestrategies.
FormoreinformationaboutThomas,youcancheckhispersonalblogatdppl6++sss*pdki]ofkko*^a.
ABOUTTHEAUTHORSxxivNancyNicolaisenisanauthor,aresearcher,andaformercomputerscienceprofessor,spe-cializinginthedesignanddevelopmentofsmallandembeddedmobile-device–basedsolu-tions.
Herthreeprogrammingbookshavebeenprintedinfivelanguages.
ShewritesfeatureandanalysiscontentforInternet-basedpublishersincludingJupitermedia,CodeGuru,andFaulknerInformationServicesandhaspublishedhundredsoffeaturearticles,columns,andanalysesininternationallycirculatedpublicationsincludingBYTE,PCMagazine,WindowsSources,ComputerShopper,Dr.
Dobb'sJournalofSoftwareEngineering,MicrosoftSystemsJournal,DataBasedAdvisor,andTelecomAdvisor,andforMcGraw-Hill/DATAPROResearchCorporation.
Lookforherfirstconsumer-orientedbook,GettingStartedwithNetbooks,whichwillbepub-lishedbyfriendsofEDin2009.
GettingStartedwithNetbooksisaplain-languageguidetoshoppingforbestfitandvalueinyournewultra-mobilecomputerandlearninghowtogetthemostoutoftheconnectedmobilelifestyleusingcloudcomputingservicesandinnovativeaccessories.
ABOUTTHETECHNICALREVIEWERxxvBruceTangisafreelancewebdesigner,visualprogrammer,andauthorfromHongKong.
HismaincreativeinterestisgeneratingstunningvisualeffectsusingFlashorProcessing.
BrucehasbeenanavidFlashusersinceFlash4,whenhebeganusingFlashtocreategames,websites,andothermultimediacontent.
AfterseveralyearsofActionScripting,hefoundhimselfincreasinglydrawntowardvisualpro-grammingandcomputationalart.
Helikestointegratemathandphysicsintohiswork,simulating3Dandotherreal-lifeexperiencesonscreen.
HisfirstFlashbookwaspublishedinOctober2005.
Bruce'sfolio,featuringFlashandProcessingpieces,canbefoundatsss*^ap]nq_a*_kiandhisblogatsss*^ap]nq_a*_ki+^hkc.
Thecoverimageusesahigh-resolutionHenonphasedia-gramgeneratedbyBrucewithProcessing,whichhefeelsisanidealtoolforsuchexperiments.
Henonisastrangeattractorcreatedbyiteratingthroughsomeequationstocalculatethecoordinatesofmillionsofpoints.
Thepointsarethenplottedwithanassignedcolor.
xn+1=xncos(a)–(yn–xnp)sin(a)yn+1=xnsin(a)+(yn-xnp)cos(a)ABOUTTHECOVERIMAGEDESIGNERxxviThisbook,asyoucanimagine,isthecollectiveeffortofawholeteamoveratfriendsofED,andIwouldliketothankeachandeveryoneofyouforthesuperbteameffortingettingthisbookoutinarelativelyshortamountoftime.
Specifically,IwouldliketothankClayAndresforhelpingmakeanideaintothisbook.
WithoutClaysharingmyenthusiasm,thisbookwouldn'thavebeenpossible.
IwouldalsoliketothankTomWelsh,whomadesuretospeakwhat'sonhismindaboutkeepingreaders'interestandensuringthehighqualityofthisbook.
Also,thankstoNancyNicolaisenforanexcellenttechnicalreviewandthecontributionofthefirstfewpagesinChapter15,aswellasmanyideasinthisbook'schapters.
Also,thankstoSofiaMarchantforensuringthatthisbookstayedontrackandforovercomingobstacles.
IwouldliketothankAdobeevangelistsJasonKnell,RyanStewart,andKevinHoytforhelpingmekeepintouchwithchangesthatweremadeinAdobe'slineofproductsandinspiringmewhilewritingthisbook.
SpecialthanksgototheAdobeStrobeTeam,andinparticulartoChristineYarrowandSumnerPaine,whowerekindenoughtoallowuspublishingandnever-before-seeninformationabouttheframework.
IwouldliketothankmycoauthorsScottJanousekandThomasJoos,whoworkeddayandnighttomakedeadlineswhilejugglingbusyschedulesandpersonallives.
Finally,IwouldliketothankthemobileandFlashcommunitiesforbeingactiveandhelpinginspiremuchofthisbook'smaterial,aswellasforkeepingupwiththefragmentedmobileecosystem.
EladElromManythankstoAlessandroPace,DaleRankine,MarkDoherty,andmanyotherpassionatelead-ersintheworldwideAdobecommunityforthehoursspentevangelizingFlashonmobileanddevicesovertheyears.
TheFlashmobile(andespeciallytheFlashLite)communityisatight-knitgroupofgreatpeoplewhoarealwayswillingtoshareopinions,resources,ideas,andknowl-edge.
Ithasbeenreallygreattobeapartofthecommunityoverthepastfewyears.
Tomycoauthors,EladandThomas,thanks,guys,forhanginginthereasweputinallthoselonghourstomakethisbeastofabookactuallyhappen(finally).
ACKNOWLEDGMENTSxxviiIalsowanttogivebigpropstothefriendsofEDteamformanagingthewholebook'sprocessandgettingitouttoreaders,despitemanyoftheobstacleswe'veencounteredalongtheway.
ThepublishingteamatfriendsofEDrocks!
ScottJanousekIwouldliketothanktheentiremultimediaandcommunicationtechnology(MCT)crewattheTechnicalUniversityofWest–Flandersfordoingafantasticjobprovidinghigh-qualityandnew-media–relatededucation.
GoingforMCTwasoneofthebestdecisionsImadeandreallyhelpedmefindoutwhatIwantedtodo.
SpecialthanksgotoKoenDeWeggheleire,whohasalwaysinspiredandmotivatedmetogetthemostoutofmyprojectsandmygoals.
ManythankstomycoauthorsEladElromandScottJanousek,whoworkedsohardtomakethisbookgreat.
Besidesthat,Iwouldliketothankyoubothfortakingmeunderyourwings.
Eventhoughtherewerelotsoflatenightsandlonghours,itwasawonderfulexperience,andIamveryproudoftheresult.
TotheentirefriendsofEDcrew,thanksformanagingthewholebook'sprocessanddoingagreatjobgettingthisbookouttoreaders.
Itwasarealpleasureworkingwithallofyou.
ThomasJoosxxviiiTheideaofwritingthisbookemergedfromthelastbookEladcoauthoredcalledAdvancEDFlex3.
Inthepreviousbook,Eladwrotean80-pagechapteraboutmobiledevices.
Beforethatbookwasprinted,theteamrealizedthatwritingachaptercoveringFlashLitemaynotbesuit-ableforaFlex3book,andthechapterwasdropped.
AfteraconversationwithClayAndresinManhattanabouttrends,technology,Flex,andmobile,EladandClaydecidedthattheyshoulddotheextraordinaryandcombineFlashLitewithemergingtechnologies,takingintoaccountthereleaseofFlashPlayer10onmobiledevices;theyalsodecidedtoincludethehard-to-keep-up-withchangestoFlashLite.
Shortlyafter,EladwasconnectedwithScottJanousekandThomasJoos,whosharedhisvisionandhelpedcreatethisbook—itincludestheory,relevantreal-lifeexamples,aswellasnever-before-seentutorialsandinformationonhowtodevelopapplicationsformobiledevicesusingtheFlashplatform.
Mobiledevicesarethemostfrequentlyuseddevicesworldwide,andtoday,themobileeco-systemisundergoinganexcitingrevolution.
AmidallthesechangesistheAdobeOpenSourceProject,whichismovingfromanideaintoarealitywiththeavailabilityofFlashPlayer10andAdobeIntegratedRuntime(AIR)formobiledevices.
Theseexcitingchangesopenupnewpos-sibilitiesformobiledevelopersandallowyoutocreatecross-platformapplicationsthatsharecodeacrossthedevices.
Thebookisagoodstartingpointifyou'readeveloperinterestedingettinginvolvedinmobiledevelopmentusingtheFlashplatform,andit'sanequallyagreatresourcefortakingmobiledevelopmenttothenextlevelandmovingtomoreadvancedtopicsandunderstandingwheremobiledevelopmentisgoing.
Thisbookissuitableformanyindividuals,whetheryou'reacur-rentFlashLitedeveloperwhowantstopushthelimitsandbetterunderstandthemobileecosys-temoraFlexdeveloperwho'sbeenreluctanttodevelopapplicationsformobiledevelopmentbecauseyourefusedtowriteyourcodeinActionScript2.
0.
Thisbookisalsosuitableifyou'readeveloperwhohasneverusedtheFlashplatformtodevelopamobileapplicationbutwantstobepartoftheexcitingpossibilities.
Thebookoffersyouunparalleledinsightintothemobiledevelopmentworld,whichisknownforbeingrewarding,aswellascomplex,fragmented,andrapidlychanging.
ThechaptersinthisbookwillcoverdifferentversionsofFlashcontentusingFlashPlayer1.
1,2.
0,2.
1,3.
0,3.
1,9.
0,and10.
0.
TopicscoveredinthisbookincludedesktopandmobiledevelopmentusingAIR,aswellasdifferencesbetweendesktopandwebdevelopment—aswellashowtotakethesedif-ferencesintoconsiderationinmobiledevelopment.
Thisbookincludesinformationregardingexistingplatforms,contentproviders,andaggregatorsthatarepartoftheworldwidemobileecosystem.
Italsotalksaboutthecommunitiesanddesktopandonlinetoolstomakeyourlifeeasier,anditoffersexcitingtutorialsforconceptssuchasdeployingFlashontheiPhoneanddevelopingmobileapplicationsusingFlashCatalyst,Flex,andAIR.
INTRODUCTIONxxixWebelievethatthisbookisagreatresourcebutalsoawindowintothefutureofmobiledevelopment:itaddressesnotonlychallengesthatmobiledevelopersfacetodaybutthenewchallengesdeveloperswillbefacingindevelopingapplicationswithFlashPlayer10andAIRformobiledevices.
Ourhopeisthatthisbookwillinspireyoutostartdevelopingapplicationsformobiledevices.
LayoutconventionsTokeepthisbookasclearandeasytofollowaspossible,thefollowingtextconventionsareusedthroughout.
Codeispresentedinbeta`)se`pdbkjp.
Neworchangedcodeisnormallypresentedin^kh`beta`)se`pdbkjp.
Pseudo-codeandvariableinputarewritteninep]he_beta`)se`pdbkjp.
MenucommandsarewrittenintheformMenuSubmenuSubmenu.
Wherewewanttodrawyourattentiontosomething,we'vehighlighteditlikethis:Ahem,don'tsaywedidn'twarnyou.
Sometimescodewon'tfitonasinglelineinabook.
Wherethishappens,weuseanarrowlikethis:.
Pdeoeo]ranu(ranuhkjcoa_pekjkb_k`apd]podkqh`^asneppaj]hhkjpdao]iahejasepdkqp]^na]g*