Category Archives: Tutorials

Connecting to CVS & SVN Repositories with Eclipse – Eclipse for Flash Dummies Series

I’m sure this is old hat for all the “real” developers in the Flash community, but I recently began exploring downloading source files from CVS and Subversion using Eclipse. CVS and Subversion are version control repositories which allow you to track the history of source files. They are especially useful for teams where multiple developers may be working on projects at the same time. However, with the explosion of the OSFlash movement it is now necessary for Flash developers to understand how to download the source files for the various projects exposed on the OSFlash Wiki which do not provide binaries (executables or installers).

The process for using both CVS and Subversion with Eclipse is similar, however Subversion requires an additional plugin, Subclipse, while CVS is a native part of Eclipse. I’ve provided captivate tutorials on how to connect to both repository types and create projects based on them below (as an added plus, if you’ve ever wanted to download and compile the source for your favorite Apache products you should now be armed with the capability to do so).

Connecting to a CVS repository tutorial

Setup Subclipse and connect to a Subversion repository tutorial

Enjoy!

Organizing Eclipse Projects With Working Sets

One of the more useful features of the Eclipse platform is the organizational capabilities it gives you. In particular, Working Sets allow you to group your projects together in logical categories or sets. What’s really nice is that a project can belong to more that one Working Set which allows you enormous flexibility in how you classify and work with projects. For example, I’ve broken my projects into Java and Flash sets and “work” and “experimental” sets as well as a catch all “all projects” set. One thing to keep in mind is that you can use Eclipse and its powerful organizational capibilities with projects which are not related to coding at all. As an example, I use Eclipse at the office to organize all RoboHelp Documentation Projects. I’ve included a Captivate movie which walks you through setting up a working set, or you can follow the steps below.

  1. In the Package Explorer pane click the drop-down arrow menu and choose “Select Working Set” from the drop down menu.
  2. Click the “New…” button from the Select Working Set Dialog window.
  3. Choose the Working Set Type you wish to create and click Next.
  4. Create a name for your Working Set in the provided input text field.
  5. Select the projects you wish to add to your new Working Set by selecting the appropriate check boxes and click Finish.
  6. Now select the Package Explorer’s drop-down arrow menu again and choose the “Show” menu item. Verify that the “Working Sets” sub-menu item is selected and not the “Projects” sub-menu.
  7. Create as many Working Sets as you desire.
  8. Go back to the Package Explorer’s drop-down menu arrow menu and choose the “Select Working Sets” menu item again.
  9. Use the check boxes in the Select Working Sets dialog box to toggle on the Working Sets you wish to be viewable in the Package Explorer and click OK.
  10. The selected Working Sets should now be visible in the Package Explorer.

Event-Based LMS / Flash Communication

Those who work in the eLearning field, know that Flash SCO (Shareable Content Object) to LMS (Learning Management System) communication is an ugly mess. The SCORM RTE specification requires JavaScript as the communication bridge between a SCO and and the LMS. JavaScript is asynchronous in nature which means that any time you make a request for information from the LMS you must enter into some type of “loop” waiting for a response–typically this takes the form of an interval, or a frame based loop. In the past I’ve used setInterval to evaluate whether properties returned from the LMS have changed, but this always felt rather ugly to me so I decided to implement an event based system which uses Object.watch and EventDispatcher. Here’s what I came up with:

/**
* @author Paul Brooks Andrus
* Creative Commons License
* http://creativecommons.org/licenses/by/2.5/
* This work is licensed under a Creative Commons Attribution 2.5 License
* June 6, 2005
*/

import mx.events.EventDispatcher;
import mx.utils.Delegate;

class Watcher {

function dispatchEvent(){};
function addEventListener(){};
function removeEventListener(){};

function Watcher() {
EventDispatcher.initialize(this);
}

/*
* Creates a watched property using the scope of the first parameter
*
*/
public function watchProp(s:Object, p:String):Void {
s.watch(p, Delegate.create(this,returnProperty), s);
}

/*
* Removes watch from the scope defined by the 4th parameter, returns
* the value of the watched property and dispatches an event object
* with all the information from the watch
*
*/
public function returnProperty(p:String,ov:String,nv:String,s:Object){
s.unwatch(p);
dispatchEvent({type:"change", prop:p,value:nv,old:ov});
return nv;
}
}

The solution, as you can see, is simple, reusable, very clean and allows the use of the familiar event-listener model. You can download the source here.

Eclipse ASDT Editor Templates

I must confess that I’ve been an avid Flash blog reader for some time now, but had been too lazy (and perhaps a bit insecure) to set my own up. However, I realized the time had come when I started emailing Jesse Warden aka Jester XL with “ideas” for him to blog–Jesse’s response was, per norm, funny as hell, “dude, blog it yourself.” And so here I am posting the “blog idea” that I was pestering Jesse with.

Like many in the Flash community, I began playing around with the Eclipse platform, ASDT editor, MTASC and Flashout (“FAME” ala Jesse) back in March following Carlos Rovira’s excellent article detailing installation, configuration and use. However, as someone with a primarily Flash background who had lived in the Flash IDE exclusively I found many aspects of Eclipse to be a bit daunting (the dreaded IDE learning curve), but after several months of exploration the light finally came on and I’ve gotta say Eclipse rocks! There are many reasons why I’ve totally fallen for this platform, but today I’d like to discuss ASDT editor templates (I’ll be extracting portions of the email exchange with Jesse on this topic so note the context).

Editor templates are simply code templates which can be invoked by typing in a shortcut command (i.e. “singleton” or “class”) and hitting CTRL+ SPACE on your keyboard. The are some useful default templates which are part of the ASDT plugin editor, but I’ve found that everything really needs to be modified to taste and customized to reflect user specific attributes. As I said to Jesse, “I’ve been using Flash in Eclipse for almost 2 months and I know it was not readily apparent how to use the shortcut commands, or how to edit and create new templates. Now that I’ve figured them out and begun using them, it has further cemented my love for the ASDT editor.” I also included a rather quick and dirty Captivate tutorial, found here, which detailed where to find the editor templates, how to modify existing templates, create new templates and use them in your code.

As an example, here’s template code which creates the class structure with the EventDispatcher mixin included:


/**
 * @author Paul Brooks Andrus
 * Copyright BadAttitude Productions
 * ${date}
 */ 

import mx.events.EventDispatcher; 

class ${enclosing_package_and_type} { 

     function dispatchEvent(){};
     function addEventListener(){};
     function removeEventListener(){};
                 
    /**
     * Constructor
    /*
     function ${enclosing_type}(${cargs}) {

        EventDispatcher.initialize(this);
        ${todo}

    }
        ${cursor}
}

The nice thing about the templates is not only do they save you a ton of typing, but you can also use variables which are represented by the styntax ${variable name}.

Another thing everyone should do is look at the Java editor templates and mine them for goodies (as an example, I took the switch statement template and modified it to taste).

Eclipse is a very powerful platform with a plethora of rich features, of which I have discovered but I few–Working Sets are awesome–and I hope some of you benefit from my learning curve. If you have other insights I would love to hear about them.