Exploiting Flash MX 2004 Features

[ LiB ]  

In the last two revisions, Flash has grown up to become a formidable development environment. It really pays to take the time to learn how the newer features can save you time. Every minute you spend learning a new trick will pay back in hours of time saved down the road. The following sections cover some of my favorite newer features and what they mean to your productivity.

Find and Replace

It sounds so innocuous , but the new Find and Replace feature is a super time saver. On the one hand, you should strive to keep your files simple andif nothing elsemodular. A big complex file is difficult to update, troubleshoot, and can also negatively affect performance. On the other hand, there are times when the nature of your project requires lots of discrete elements. For example, you may need to import hundreds of small icon graphics. If you were displaying large images, you would probably want to look at loadMovie() to import at runtime but importing many small items is best handled in one swoop. Find and Replace provides a slew of hidden gems that avoid repetitive tasks .

I haven't personally had too many occasions to use Flash 2004 in actual projects, but I have enough experience in older versions to see how Find and Replace would have helped me.

Obviously, you'll have your own occasions to use Find and Replace. In any event, be sure to check it out. Incidentally, to search your scripts, you need to use the Find and Replace option in the Actions panel. More about the Actions panel next !

Actions Panel Tricks

Several features built in to the Actions panel are worth learning. (By the way, most of the following features are also available if you use Flash MX Professional 2004 as a text editor to edit plain AS script files.) It's probably impossible to miss some of these features, but I think it makes sense to touch on a few things that, if you're not, you should be using.


First, realize that although the toolbox on the left side of the Actions panel is useful to hunt down or just explore for elements in the ActionScript language, it's not exhaustive. Interestingly, you can supplement the content that appears in the toolbox by creating and placing XML files in Flash's Configuration folder. I'm not going to document the format, but it's not a huge task to duplicate one of the XML files you find under ActionsPanel/CustomActions and then tinker on your own... trying edits and viewing the results. My main point is the toolbox is extensible.


Finding Your Local Configuration and Application-Level Configuration Files

The easiest way to find your configuration files is by looking for the folder named en, adjacent to your installed version of Flash (en standing for Englishlook for es if you're Spanish, for example). There are two folders: First Run and Configuration . Everything in the First Run folder gets copied into your local Configuration folder every time Flash launches. The idea is that if someone else logs on to your machine and runs Flash, the First Run folder gets copied to that user's local Configuration folder. This way it's possible to have personalized settings for each user . Just realize that if you make a change to the First Run folder, you must quit and restart Flash to see the changes. In addition to First Run, you'll find a folder adjacent to Flash called Configuration . This is the application-level Configuration folder with items that don't vary from user to user. After you've run Flash MX 2004 at least once you'll find your local Configuration folder (called Configuration although it's a copy of First Run ) in the following paths:

Windows XP/2000:

 C:\Documents and Settings\ Phillip \Local Settings\Application Data\Macromedia\Flash MX 2004\en\Configuration 

Replace Phillip with your login name . Also, if you can't find the preceding folder, you may need to select the following option from Windows Explorer: Tools, Folder Options, Show Hidden Files and Folder.

Mac OSX:

 Users:phillip:Library:Application Support:Macromedia:Flash 2004:en:Configuration 

Again, replace Phillip with your login name.

Code Hints

No doubt you know this one. For example, type test_btn . and the instant you type the period, a code-completion tip for Button methods appears (see Figure 10.1). You may also know that like the Actions toolbox, you can customize these code hint suffixes via the AsCodeHints.xml configuration file. What you may not know is that new for Flash MX 2004, you can define your own code-completion triggers inline with your ActionScript.

Figure 10.1. Several objects have designated suffixes, such as _btn for buttons .


The new way to get code hints builds off the strict data type casting feature in Flash MX 2004 (discussed in Chapter 4, "Working with Complex Data").

When you cast a variable name as a particular data type, the code completion for that data type appears for that name. It's really easy: just start by typing:

var myVariable:

As soon as you type the colon casting identifier, you'll see a pop-up list of all the built-in data typesincluding classes for the components . Pick a data type and then continue on your way (either with a new line or to fill the variable with its default value). Then, anywhere later in that script, you'll get the code-completion hints anytime you use that variable name. Figure 10.2 shows a simple case where I first cast myB as a Button to get all the code hints. In some casessuch as when casting component instancesyou'll need to include the path to the class file. For example, to cast myCB as a ComboBox, use var myCB:mx.controls.ComboBox . That's because the ComboBox class is in the folder Classes/mx/controls.

Figure 10.2. After casting your variable as a particular type, the appropriate code-completion hints appear.


Even if you don't fully exploit strong data type casting, it's hard not to take advantage of this gem.

Code Navigator

On the left side of the Actions panel, underneath the "toolbox" of ActionScript references, you'll find a collapsible pane called the Code Navigator. Those familiar with Flash MX can think of this as a Movie Explorer but for code only. The Code Navigator gives you direct access to all the scripts in your movie. Although it's really best to keep your code as centralized as possible, I still find occasionsespecially while prototypingwhen putting code in separate frames is convenient . For example, Figure 10.3 shows how the Code Navigator enables me to jump around to different keyframes in my application.

Figure 10.3. The Code Navigator pane (lower left) provides access to all your application's scripts.


Single-clicking a script jumps you to that script, whereas double-clicking in addition "pins" the script. Pinned scripts appear as additional tabs to the right of the script current selection (see the bottom of Figure 10.3). Incidentally, you can pin a script manually when you know you'll be returning to a particular script.

Code Cleanup

It's not that programmers are neat nicks. If anything, the reason why we keep code clean is to make it easier to troubleshoot. Do yourself a favor and strive to write clean code even if it seems to slow you down. The Auto Format button in the Actions panel will help by inserting tabs appropriately when your syntax is complete. I usually start by writing code that, although containing no script errors, is somewhat meaninglessbut formatted properly. For example, I'll type out the if statement as so:

 if(condition){ //do stuff } 

Then, I press the Auto Format button. The word condition is legitimate syntax, but will be replaced with my actual condition. The thing is, I don't have to complete that part just to get the basic skeleton formatted right.

Again, you have to have proper syntax before auto format will work. I recently learned a neat trick that will help you balance things such as parentheses, brackets, and curly braces. While editing a script, if you do a Ctrl+' (that's Ctrl and the apostrophe), the entire currently enclosed code block gets selected. Not only does it help identify where you are in your script, but you also can use this to quickly and accurately select a large block of code (for example, the entire else part of a huge if statement). Check it out; I can't believe I went so long without knowing this one.

There are probably other hidden or underused features for scripting. Just remember taking the time to learn these tricks pays back many times over.


Flash MX 2004 introduced scripted control of the Flash authoring tool. This means nearly anything you can do with the mouse, keyboard, and a human can be re-created in code. The code is written in JavaScript Flash (JSFL) and only runs at authortime on a machine that has Flash installed. In fact you can set it to run unattended. Normally, you just select and run such scripts from Flash's Commands menu.

Although this feature will unlikely remove the need for humans altogether, it will be quite handy once people write a few nice utility Commands. Initially, your copy of Flash won't have any Commands. You can follow the menu Commands, Get More Commands to browse for some built by others. But they're very easy to create yourself. Chapter 13, "Building a Code Library," walks you through how to create a Command that changes the offstage color . (Basically, the Command draws a shape just in that area.) In fact, making a Command is as simple as selecting a few lines in the History panel and pressing the Save As Command button. For now, just realize that Commands can eliminate mundane, repetitive, or meticulous tasks.

Commands may also run from a custom panel. Such Window SWFs will show up in your Window menu, provided that a SWF is installed inside the WindowSWF configuration folder (not unlike the CustomActions folder discussed earlier). Actually, any movie can serve as a WindowSWF, but only ones that perform some useful task make any sense.

It turns out it's not absolutely necessary that you learn how the various configuration files work and where they get installed. When installing extensions built by other developers, the Macromedia Extension Manager (free from www.macromedia.com/exchange/em_download/) takes care of installing the right files. When you want to quickly create your own extensions, however, it helps to have a working understanding of the various configuration files. If nothing else, snooping through these files can be very enlightening.

Although this section would spin out of control if I were to try and document how to write advanced Commands, let me make a few suggestions in case you want to venture into custom Commands. First, anyone can make a simple Command using the History panel. Just do the steps manually and select the appropriate rows in the History panel and then press the Save As Command button (see Figure 10.4).

Figure 10.4. You can make a Command by just saving steps recorded in the History panel.


For more about the JavaScript Flash (JSFL) language used for Commands, check out Chapter 13.

Project Panel

Flash MX Professional 2004's Project panel has two main benefits:

  • An easier way to manage and track projects that involve multiple files

  • A version-control tracking system to ensure no two developers are working on the same file

If you're a single developer, the Project panel is nice because it helps you keep all related files in one place. When you create a new project, you create a single FLP file and then add all files related to your project. This can include FLAs, SWFs, HTML, MP3s, JPGs, FLVs, and various text data files. When you return to work on a project, you just open the FLP and all the connected files are available through the single interface (shown in Figure 10.5).

Figure 10.5. The Project panel enables you to manage all the files related to your project through a single interface.


Another management benefit is the Test Project feature. You must identify one file as the default document. The main index.html file is a logical choice. It's the default document that you'll view when testing a project. The cool part, however, is that all your open files from the project also get published according to the publish profile you specify. This feature alone can save you a ton of legwork publishing multiple files.

The version-control side of the Project panel is more sophisticated. The main idea is that you can have several developers working on the same project and, provided they follow the correct protocol, no two people will think they're working on the master version of a file. You need to keep the master files in a single shared location, such as a network drive. After everything is set up, here's how the scenario will play out: Developer one checks out a file, the master version of that file gets copied to developer one's computer, and the copy on the network is marked as checked out. If another developer attempts to check out that file, the developer is told that developer one has it checked out. When developer one is done working, she checks the file back in, making it available for check out by anyone else. In addition, the local copy developer one was working on is also marked as locked; if she tries opening it later, she is notified that she should first check out the master from the network to ensure she has the most up-to-date version.

That scenario is ensured if everyone follows the rule to always check out files and check them back in. Actually, if one developer checks out the file and then decides not to save his changes, that developer can "undo check out," which is like checking the file back in (because it's marked as available), but it doesn't upload the file with which he was working.

Setting up and using the Project panel correctly requires that you understand how it works and that you don't expect it to be something it isn't. Because I was familiar with Dreamweaver's Site panel, I had the false impression the Project panel helped you deploy sites. In Dreamweaver, every file you work on is part of your site. In Flash, however, your primary files are FLAs, which you don't want to post. For this reason, you need to handle any deployment manually.

The following subsections provide a quick rundown of how you can use the Project panel for both management and version control.

Managing Files

If you just want to manage a bunch of related files, just select New Project and save a FLP file. Then select Add File for all the files you want to track. You also can specify separate publish profiles for each FLA in your project. Of course, you must first define profiles from the Publish Settings dialog box. Then you can select Settings from the Project panel's main menu (see Figure 10.6).

Figure 10.6. After you define site profiles, you can associate a project with any site.


The top section of the Settings dialog box (as well as the second menu in the Project panel) is only needed for version control.

Setting Up Version Control

To use version control, you first need to define a site and then associate your project file with a particular site. Actually, Flash MX Professional 2004 automatically displays any sites you've previously defined with Dreamweaver MX 2004. You can define sites by first selecting Edit Sites from the Version Control menu (the second one in the Project panel). Sites include a given name, a local location for files, your email and name (so other developers can contact you if you have a file checked out), and a remote location for the master version of each file (see Figure 10.7).

Figure 10.7. Site definitions include a local and remote directory plus a name and email so that others know who has a file checked out.


You'll see options to store remote files on an FTP site, a network, or in Microsoft Visual SourceSafe. (You may likely find a third-party extension to support other tools such as CVSbut nothing else is available at this time.) Because there are additional restrictions on FTP, I recommend you perform initial tests using the Local/Network option.

After you have a site defined, you can associate your project to one via the Settings dialog box (shown in Figure 10.6). Actually, you'll be prompted to do this as soon as you attempt to check out any files.

Using Version Control

With your project associated with a site, you can start using version control. The first step should be to check in each and every file in your project. This might sound strange , because you would expect to first check the files out . To make the files available to others on your team, however, you need to check them in for the files to upload. To begin working, select the file and choose Check Out (from the Version Control menu or right-click the context menu). Perform all your edits on that file and when you're done, save and then Check In. Realize that if you ever click Test Project, you'll see the published versions of all checked out files, but only the most recent local copy of any files you haven't checked out. If you have a bunch of JPGs that load dynamically, it may not be an issue that you may be viewing old versions of those files. If you want to bring your local copies into synchronization, just check out all the files and immediately Undo Check Out so that others can check out those files.

For others to start accessing your project files, they must first define their own site that uses the same remote folder. However, each of your coworkers won't have to define his or her own project file (and point to files) like you did initially. All they need to do is select File, Open from Site. That dialog box enables them to select any of their site definitions, and then it connects to get a list of files available in the remote folder. Then they can select just the FLP file. Flash then prompts the users that they can update "missing" project files. This just downloads a local copy of all the files in the project. For me, it's a lot easier to use the Project panel in a real project after first walking through several test scenarios.

Finally, remember that after you check in a file, your local copies are marked as read onlyforcing you to first check out files before working on them again. I think the best tip I can give is not to try to make the Project panel something it's not. It's a very convenient way to keep related files together and it can prevent two coworkers from working on the same file simultaneously .

[ LiB ]  

Macromedia Flash MX 2004 for Rich Internet Applications
Macromedia Flash MX 2004 for Rich Internet Applications
ISBN: 0735713669
EAN: 2147483647
Year: 2002
Pages: 120

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net