In the publish settings, you have the option (on by default) to have named child instances inside a particular MovieClip instance declared in the created class automatically.

Suppose we have a class MainController as Document Class, and a library item instanced on the root timeline with name “myClip_mc”. When automatically declaring instances, I can talk to a member property myClip_mc inside my MainController class. That may sound handy, but any self-respecting code editor with checking will start nagging that myClip_mc has not been declared. And since it hasn’t been declared, it’s untyped, therefore we don’t have code hinting. So not that handy after all.

Now let’s not declare instances automatically. Since we didn’t declare anything in the MainController class, the Flash player will try adding myClip_mc at runtime to the MainController instance, and fail with a runtime error, provided you didn’t declare MainController as a dynamic class. And you shouldn’t. So we add a public var myClip_mc:MovieClip (yes, public!) to our MainController, we get code hinting & compile time type checking, and everything compiles and runs fine. Perfect.

Well… suppose, for the sake of convience, or out of laziness, or for whatever reason, we happen to have a bunch of named instances on our timeline that we will look into later. We haven’t come to that part yet, so we haven’t bothered declaring them in the MainController class… Wrong! We’ll get a runtime error for the first undeclared named instance that can’t be added, after which the Flash player stops.

So to quote Cruijff, every upside has its downside. The good thing is of course that now at least we get a runtime error if we typed the instance name wrong in the class vs. the timeline.

29 Aug, 2007, 14:30 o'clock

I guess, even as a Windows developer, you will notice it when your Interaction Designer and/or Visual Designer has a Mac. About every effect Mac OS X offers, has to be repeated at some point in some Flash application. So can do you all of the following?

  • mirroring
  • Expose
  • Icon Dock
  • iTunes
  • Coverflow
  • Genie

So here’s a first version of the Genie effect. Not very flexible yet, but the direction is there. See the swf for the effect: click on the image to make it go icon, click again to make it pop back up.
The code can be found here. It requires the ASAPFramework v0.94 in your classpath, and a single image in the library with a linkage id.

28 Aug, 2007, 15:44 o'clock

With the FDT plugin, Eclipse turns your JavaDoc comments into popups that appear whenever hovering over a code that has JavaDoc comments attached to it. This can be any class, member variable or function. Attaching comments is done by putting a comment right over the element you wish to attach it to, in JavaDoc style:
/**my comment for myElement*/
myElement

For a long time, it has been a habit to use long separation lines consisting of dashes for functions. Though this may increase separation of functions in a class file a little, those long lines also appear in the popup that Eclipse creates. It is therefore strongly recommended to let go of the little dashes, and use “clean” comments, like this:
/**
*    The function description
*    @param ...: a parameter description
*    @return : description of the return value
*/

For public variables, a single line JavaDoc comment can be added on the line over the declaration:
/** objects of type MyData */
public var myList:Array;

3 Jul, 2006, 15:21 o'clock

In the series “Oneliners for Flash” this is a handy one for stopping the current timeline for a while and continuing after a certain amount of time. A nice replacement of endless inserted frames:

stop(); var interval:Number = setInterval(function () : Void {clearInterval(interval); play();}, 2000);

The number at the end, 2000, is the number of milliseconds to wait before continuing. Place this line of code in any key frame where you want to wait, and set the right number of milliseconds. Bannerfriendly and reasonably low in maintenance.

27 Jun, 2006, 23:04 o'clock

JSFL, Javascript for Flash, supports running scripts from other script files. The syntax is not very lucky, and I would have preferred something like import, but its availability allows for creation of libraries for reuse.

The file Commands.zip contains “newItem.jsfl”, that contains a few functions that come in handy when creating a new linked movieclip item. The main function is createNewLinkedMovieClip, that creates a new movieclip symbol in the specified library with a specified linkage class. The user is prompted for a name that has to be unique both as symbol name and as linkage id. If the user cancels, the script is aborted. Here’s an example of how to call this function. This example assumes that the file has been placed in a folder “includes” inside the commands folder:

var library = fl.getDocumentDOM().library;
var movieclipName = fl.runScript(fl.configURI + "Commands/includes/newItem.jsfl", "createNewLinkedMovieClip", library, "org.asapframework.ui.buttons.HilightButton");

The function returns the name of the created movieclip symbol, or “null” if the user cancelled the prompt for a name. It would be logical to stop the script if the user cancels. Now aborting a running jsfl script isn’t entirely trivial. Apparently the only way to achieve this, other than wrapping every possible abort point in an increasingly deep if {}, is by using try{} catch (). Though more advanced in use, it has the nice effect of catching errors that would normally result in a popup from Flash, and displaying a useful message in the output window. That is, provided the error message is put through to the output window:

try {
// some code here that may go terribly wrong
} catch (err) {
fl.trace("Command aborted, error = " + err);
}

In order to abort a script, an error can be thrown that will be caught in the catch (err) {} statement, like this: throw("Cancelled");

The file also contains functions for writing frame labels on consecutive key frames, and creating an actionscript layer with a stop frame in the first frame.

The other two files in the zip are complete commands for creating stubs for the HilightButton and Checkbox classes from ASAPFramework.

25 Jun, 2006, 19:44 o'clock

When defining a member variable of type Array, put a Javadoc comment (/** */) on the line above the declaration, so it will appear when hovering over a reference to the member variable. Example:

/** of type SubjectData */
private var mSubjects : Array;

23 Jun, 2006, 15:52 o'clock

Situation: You load an external swf and render it to a bitmap. On rollover, you tell it to go to another frame, and rerender it, to get the rollover image from the loaded swf. If you do this by giving it a label (gotoAndStop(“over”)), it will miss the new frame half of the time, and render the old frame. If you give it a frame number instead (gotoAndStop(2)), it’s spot on each time.
This phenomenon does not occur all the time. It might be related to CPU obsession / possession.

23 Jun, 2006, 15:50 o'clock

Twitter

Flickr

www.flickr.com
This is a Flickr badge showing public photos from AcidCats. Make your own badge here.