Browse DevX
Sign up for e-mail newsletters from DevX


Coding for a Time-based Medium  : Page 4

Preparing traditional developers to develop in Flash requires some new terminology and careful separation of code and interface elements.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

One practice that carries over to Flash from traditional development is the ability to move code out of the application for easier change and version management.

Flash supports a server-side #include syntax for importing the contents of an external flat file, which means you can easily way keep code under source control and outside of Flash. For example, if the login() function shown above were defined in an external text file called Membership.as, the Flash movie could include it with the following line of code:

#include "Membership.as"

In addition to application logic, you can use external files to define application settings. Rather than republishing your Flash movies every time a server configuration or address changes, place such settings in an external file that a Flash movie reads and parses each time it runs. Often a Flash movie needs to communicate with server applications whose URIs might change, for example when moved from server to server. To avoid the risks of republishing for deployment, place the URIs in XML or plain text files that you can edit easily. Then load and read these settings in the first frame of your movie. Flash MX provides a special preprocessor-style command, #initclip, to identify ActionScript code blocks that the runtime should interpret first.

#initclip 0 var settings = new XML("settings.xml"); var1 = settings.firstChild.nodeValue; … #endinitclip

Strategy 3: Abstract Software Subsystems
Component-based software like EJBs and COM provide abstracted, standardized, reusable interfaces to applications. Components change the focus of application development from writing code line-by-line to one primarily concerned with assembling larger building blocks. Component software models have proven to save considerable time in traditional application development.

Flash offers effective ways to use software more objectively. For the first time, Flash MX offers true object support, including class inheritance. Flash MX also supports components. Unlike conventional software components, Flash components can contain either pure code or a combination of code and interface elements. Component authoring is complex enough to warrant a lengthy description of its own, but essentially, a Flash component is a Movie Clip object that developers can "register" into a namespace. New objects or clips created with a registered component namespace automatically bind to the corresponding object. In addition, the Flash MX IDE gives developers design-time control over component properties, much as ActiveX objects do for VB or VC++. The following code shows how you could create a binding for a set of membership routines such as the login method shown earlier above.

#initclip 1 function MemberManager() { ... } // object constructor // inherit MovieClip MemberManager.prototype = new MovieClip(); MemberManager.prototype.login = function (strScreenname, strPassword) { ... }Object.RegisterClass("Membership", MemberManager); #endinitclip

The Object.RegisterClass() statement lets you invoke MemberManager objects using the binding name Membership—just as you would use a COM ProgId or an EJB moniker.

var myMemberMan = new MemberManager();

Flash components are convenient, but they still don't offer the security and ease of transport that DLLs and EJBs do. While the published .swf format isn't as secure as compiled byte code, it is a good substitute. Consider publishing ActionScript-only movies that register ActionScript or MovieClip classes, then load these published movies into a layer of any Flash movie to simulate a compiled software component.

#initclip 1 loadMovie("Membership.swf", _root.membership); #endinitclip

For more on object support in Flash MX, see the ActionScript Dictionary Overview.

Final Thoughts
As Flash has evolved, it has adopted features from conventional development methodologies. With ECMAScript compliance and true object support, traditional application and web developers Flash are finding ActionScript increasingly accessible. Traditional developers excel at Flash development when they learn to treat it as just another tool for creating the same kinds of applications they create in other languages and environments. While Windows DNA or Java developers need to gain a considerable amount of Flash-specific coding knowledge to master Flash, following the techniques and best practices for time-based media development shown in this article will help make Flash more accessible.

Ian Bogost is the vice president technology for Media Revolution, an integrated marketing agency in Santa Monica, CA. Ian creates rich user experiences that fuse content delivery, eBusiness, and marketing messaging for the entertainment and consumer products industries. Ian has worked on numerous distinguished projects for high profile clients, including DreamWorks SKG, Sony Pictures Digital Entertainment, American Honda Motors, DirecTV, and Nestl´┐Ż USA. You can reach him via e-mail at ibogost@mediarevolution.com.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date