Flash .NET Pallav Nadhani Gregg Wygonik David Neal Todd Yard Chris Bizzell Graeme Bull IFlash .NET © 2002 Springer Science+Business Media New York Originally published by friends of ED in 2002 AII rights reserved. No part of this book may be reproduced. stored in a retrieval system or transmitted in any form or by any means. without the prior written permission of the publisher. except in the case of brief quotations embodied in critical articles or reviews. The authors and publisher have made every effort in the preparation of this book to ensure the accuracy of the information. However. the information contained in this book is sold without warranty. either express or implied. Neither the authors. friends of ED nor its dealers or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book. First Printed November 2002 Trademark Acknowledgements friends of ED has endeavored to provide trademark information about ali the companies and products mentioned in this book by the appropriate use of capitals. However. friends of ED cannot guarantee the accuracy of this information. ISBN 978-1-59059-167-3 ISBN 978-1-4302-5135-4 (eBook) DOI 10.1007/978-1-4302-5135-4 iFlash .NET Credits Authors Commissioning Editor Pallav Nadhani Andrew Tracey Gregg Wygonik David Neal Author Agent Todd Yard Chris Matterface Chris Bizzell Graeme Bull Project Manager Simon Brand Additional Content Dan Squier Indexer Fiona Murray Technical Reviewers Mark Grimshaw Graphic Editor Keran McKenzie Ty Bhogal David Neal Stuart Ibbotson Rama Ramachandran Matt Rice Cover Design Katy Freer Technical Editors Ty Bhogal Matthew Knight Dan Squier Managing Editor Chris Hindley Flash .NET Pallav Nadhani "Heaven doesn't need him and Hell is afraid he might take over". That's how this chemically inbalanced Kindergarten naughty boy used to trespass around people's minds. Esoteric music pulls him, the louder the better. Gets bored without constant challenges - keeps on freaking with new technologies. Hacking, Quake Ill, WWE and happening movies feature among his top likes. A programmer by heart, Flash is his first love (though ever failed to draw a trapezoid). Shacks in lnfoSoft with a Technology Architect board hanging outside it. He would like to thank his Mom and Dad for being the never ending source of inspiration, Monu for his continued support, and "Gadhri" for her petty mischiefs that kept him going throughout. [email protected] Gregg Wygonik Gregg is a professional electronic mus1c1an who spends his days developing Flash-based software that teaches mathematics to children. When not behind a computer, in the studio, or trotting around on tour, Gregg likes to spend his "free" time with his photographer wife and their three cats. Gregg tries to keep his Flash experimentations online at www.artificialcolors.com, though keeping the site current is always easier said then done. If Gregg were a colossal death robot, he'd be Gigantor, and if he were an evil criminal, he would be Elizabeth Bathory. David Neal David Neal is currently the Vice-President of Web Technology and Chief Software Architect for Transcender LLC, where he is looking for every opportunity to use his .NET skills. Outside of his passion for assimilating new technology, he fancies himself a capable fingerstyle guitarist. He would like to thank his wife Tammy and four sons Caleb, Benjamin, Christian, and Drew for their unconditional love and support, and for being the best family a man could ever wish for. You can reach him at [email protected]. Author Biographies Todd Yard After studying theatre in london, then working for several years as an actor in the US, Todd was introduced to Flash in 2000 and was quickly taken by how it allowed for both stunning creativity and programmatic logic application a truly left-brain, right brain approach to production and has not looked back. He now works as Creative Director for Daedalus Media in New York City, which specializes in the creation of Flash-based corporate presentations primarily for clients in the investment banking industry. His more frivolous work and experimentation can be found at his personal website www.27Bobs.com. Chris Bizzell As web developer for The Pinnacle Consulting Group, Chris has developed numerous dynamic web applications using ASP and ASP.NET and is excited by the endless possibilities of incorporating server-side technologies with Flash MX. After picking up a demo of Flash 4 two years ago, he became hooked on the Macromedia product line and is amazed at the steady maturation of the Flash software. When not playing with his children Cassidy and Brady Chris likes to kick around his hometown of Greenville with his wife Stacy. Thanks: I would like to thank my wife Stacy for putting up with me while this project was being completed. I would also like to thank West Goewey for getting me started, and Todd Scott and everyone at Pinnacle for giving me a chance to do something I truly enjoy for a living. Graeme Bull I never really had any real mind to get into web design or anything of the sort until about two years ago, though after being infected with the Flash and Photoshop virus, I can't put down my mouse, to a point where I'll just plain forget to eat and drink as I stare hard at my screen trying to get that perfect collage of pixels to come together for some fantastic creation. This is where I have got to thank my girl for coming by and bringing food to sustain me so I can continue the staring, pixel-moving and general mumbling at the screen. Flash .NET Introduction 1 Power at what price? ...................................................................................................... 2 How the book is structured ........................................................................................ 2 What you'll need ............................................................................................................. .3 Code downloads ............................................................................................................. .3 Layout conventions ........................................................................................................ 4 Support-we're here to help ...................................................................................... S chapter 1: Flash and .NET 9 Clients and servers ........................................................................................................ 10 Dynamic content .......................................................................................................... 12 ASP or ASP.NET? ............................................................................................................ 13 Installing the liS web server ...................................................................................... 14 Testing the liS installation .......................................................................................... 15 Calling up a web page ................................................................................................ 16 A new start ...................................................................................................................... 17 Careful coding ................................................................................................................ 19 Objects, objects everywhere ...................................................................................... 20 General syntax ................................................................................................................ 21 Variables and data types ............................................................................................ 22 Converting data types .................................................................................................. 22 Operators ........................................................................................................................ 23 Loops and conditionals ................................................................................................ 23 Flash clients .................................................................................................................... 24 Avoiding cached data ................................................................................................. .31 chapter 2: Talking to the server 35 Flat data ......................................................................................................................... .35 Sharing flat data with the server .............................................................................. 36 Using LoadVars to pull in data from the server .................................................. 37 Using LoadVars to send data to the server .......................................................... 41 Structured data ............................................................................................................. .47 Understanding XML ..................................................................................................... .48 Working with XML in Flash ....................................................................................... .49 Writing ASP.NET pages that generate XML ............................................................ 55 Rich content .................................................................................................................... 60 Setting up ........................................................................................................................ 65 Limit scrollbar ................................................................................................................ 66 Scale and the zoom buttons ...................................................................................... 66 Scroll pane and the refresh button ........................................................................ 67 Zooming ..........................................................................................................................6 7 Updating the image ...................................................................................................... 68 Table of Contents chapter 3: Storing and sourcing data 73 Different sources of data ............................................................................................7 4 Setting up read/write access ...................................................................................... 7S Setting up the passwords ............................................................................................ 78 Defining the secure content ...................................................................................... 79 Building the ASP.NET page ........................................................................................ 79 Building the Flash front-end ...................................................................................... 82 Setting up the hit count .............................................................................................. 86 Building the ASP.NET page ........................................................................................ 86 Building the Flash front-end ...................................................................................... 89 Defining the news stories .......................................................................................... 91 Building the ASP.NET news reader page ................................................................9 2 Building the basic Flash front-end .......................................................................... 95 Building the ASP.NET admin page .......................................................................... 101 Building the Flash ad min interface ........................................................................ 10 4 Image gallery ................................................................................................................ 10 8 Using TerraServer ........................................................................................................ 113 chapter 4: Databases 123 Introducing MSDE ...................................................................................................... 125 Installing and configuring MSDE ............................................................................ 125 Talking to databases with .NET .............................................................................. 128 Designing the ASP.NET web service ...................................................................... 140 Designing the Flash MX solution ............................................................................ 141 Scripts for StartFrame (frames 1-1 0) .................................................................... 164 Scripts for ReadMessage (frames 11-20) .............................................................. 171 Scripts for NewMessage (21-30) ............................................................................ 172 Scripts for NewUser (frames 31-40) ...................................................................... 174 Scripts for LoginForm (frames 41-50) .................................................................. 176 chapter 5: Flash Remoting 183 Flash Remoting components .................................................................................. 184 Installing the Flash Remoting service for .NET .................................................. 184 Testing the installation .............................................................................................. 186 Writing a service function ........................................................................................ 187 Building the client ...................................................................................................... 188 Connecting to the server .......................................................................................... 189 Using the service object ............................................................................................ 189 Handling feedback from the server ...................................................................... 190 A more flexible way to use the MM:Fiash control ............................................ 190 Different data types .................................................................................................. 193 Passing data back and forth .................................................................................... 195 Using the NetConnection Debugger .................................................................... 199 Flash .NET Custom event tracing ................................................................................................ 202 Flash Remoting and databases ................................................................................ 203 Creating the database ................................................................................................2 04 Writing the service function .................................................................................... 207 The Flash movie .......................................................................................................... 209 Flash Remoting and web services .......................................................................... 214 Using the doGoogleSearchO web method .......................................................... 218 Creating the Flash interface .................................................................................... 220 case study 1: Airport weather 227 Starting out .................................................................................................................. 228 What are the goals of the project? ...................................................................... 228 Choosing a suitable web service ............................................................................ 229 Getting to know the web service .......................................................................... 231 Service description .................................................................................................... 234 Have some class ..........................................................................................................2 41 Sticky GUI ...................................................................................................................... 244 case study 2: PenPad 267 Methods of drawing .................................................................................................. 267 Code, code, and more code .................................................................................... 268 Exploring the main timeline ....................................................................................2 70 The movie clip buttons ............................................................................................ 271 The library .................................................................................................................... 273 Extending movie clips ................................................................................................ 273 Marquee ........................................................................................................................ 274 Interface communication .......................................................................................... 275 The code not taken .................................................................................................... 278 Interface Enhancements ............................................................................................ 280 The Shape Class .......................................................................................................... 288 Anchors .......................................................................................................................... 291 Methods of manipulation ........................................................................................ 292 Drawing the curves .................................................................................................... 293 Shapes XML ..................................................................................................................2 98 Packaging the shapes ................................................................................................ 299 Sending picture data to the server ....................................................................... .300 Storing data in the file .............................................................................................. 304 Verifying the save operation .................................................................................... 305 Hang ten ....................................................................................................................... .309 Fill it up ......................................................................................................................... .309 Index 313 Table of Contents