Archive for August 8th, 2008

08th Aug 2008

An Eventful Revision

I finally got some time to play with my AnimatedClip class. I had a few ideas I wanted to try out. While playing with it, I realized that there was no real way to respond to tween events as all of the tweens resided in private instance variables. So I went back and added getter methods for the tween that I though people might like to respond to. So now you can do something like this:

//ball has com.vfd.animation.AnimatedClip linked to it via the library linkage.

import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
ball.easing= Bounce.easeInOut;
ball.sizeTo(300,300,5);
ball.widthTween.addEventListener(TweenEvent.MOTION_FINISH, motionFinished);
function motionFinished(evt:TweenEvent) {
ball.widthTween.yoyo();
ball.heightTween.yoyo();
}

Will add this into the repository when I get home. I am mostly working on the AS3 version at this point.

Posted by Posted by Jeremy Wischusen under Filed under ActionScript 3, Open Source Projects Comments No Comments »

08th Aug 2008

Word Completion in Eclipse

For a long time I used IDEs such as SEPY and Flashdevelop, however, when I work on my MAC or Linux systems, I do not have these available to me and I have yet to find a full satisfactory replacement. One of the features I love about those editors is that when I define  a variable in a file, it then becomes available in the auto-completion feature. This was great as I did not have to constantly type out all of the variables and methods I defined.

The other day I was doing some research on Eclipse for an article I am writing and discovered that Eclipse has a word completion feature. If you start typing something and then press Alt+/ Eclipse will present you with an auto-complete box with all the words that start with what you have type, or if there is only one match, it will insert it.

While this is not quite as nice as the features in SEPY and Flashdevelop, it is definitely a time saver. Additionally, since this is an Eclipse feature, it works with all sorts of file types.

Definitely a feature worth knowing about.

Posted by Posted by Jeremy Wischusen under Filed under Eclipse Comments No Comments »

08th Aug 2008

Enforcing a Singleton

Been doing some research on Cairngorm and in the process came across this little trick for enforcing singletons. ActionScript will not let you set the access modifier for a constructor to private and as such, despite having a singelton architecture, there would be nothing stopping someone from directly calling new Singleton, which defeat the purpose of a singleton in the first place. The solution involves using what amounts to a private class that is a required argument of the constructor. This looks like this:

package
{

/**
* …
* @author Jeremy Wischusen <cortex@visualflowdesigns.com>
*/
public class Singleton
{
private static var instance:Singleton;
public function Singleton(enforcer:SingletonEnforcer)
{

}
public static function getInstance():Singleton
{
if (Singleton.instance == null)
{
Singleton.instance = new Singleton(new SingletonEnforcer);
}
return Singleton.instance;

}
}

}
class SingletonEnforcer
{}

Notice the class definition for SingletonEnforcer is ourside of the package definition. When you define a class like this in the same file as a another class, it is only available to main class defined in the file (the one inside the package statement).  In other words the class is private. Since the constructor requires an instance of this class, trying to instantiate using new Singleton will throw an error since there is no way that an enforcer can be created and passed to the constructor other than within the Singleton class itself.

Hopefully in future versions of ActionScript we will have private constructors (along with method overloading just in case anyone is listening hint hint), but for now, this should do the trick.

Posted by Posted by Jeremy Wischusen under Filed under ActionScript 3, OOP Comments No Comments »