Archive for August, 2008

31st Aug 2008

Tweaking Eclipse

Eclipse is a very powerful editor, but let’s face it. It can be slow. Recently I have been doing some research into some ways I can get the thing to speed up a little and I thought I would share what I have found. As it turns out, the most detailed description I have found is in a book I own on Flex –
Flex Solutions : Essential Techniques for Flex 2 and 3 Developers by Marco Casario. It basically mirrors the resources I found online, but has more details in regards to what settings to try for particular amounts of memory.

In order to apply some of these tweaks, you will be editing the INI file for Eclipse. This file is named eclipse.ini and can be found in the root directory of wherever you installed Elcipse (e.g., C:\Program Files\eclipse).

Lets start with those tweaks first and then move on to some of the other settings you can play with once you have Eclipse open.

Once you have located the eclipse.ini, make a back up copy of it in case you need to reference to your original settings. Once you have done that, open elcipse.ini in you text editor of choice.

The default contents of my ini file looked like this:

-showsplash
org.eclipse.platform
–launcher.XXMaxPermSize
256M
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms40m
-Xmx256m

We are interested in the stuff after the -vmargs. These are the arguments that Eclipse passes to the Java Virtual Machine. By tweaking these settings, we can do things like manage the amount of memory allocated to Eclipse. To apply the tweaks, we are going to modify some of the existing arguments and add a few new ones. For the ones we add, place them at the end of the file after the -vmargs flag. If you are interested in what the specific arguments mean, go here as I am not going to go into that level of detail.

Here are the recommended settings by amount of RAM.

512 MB RAM:

-Xms256m
-Xmx256m
-XX:PermSize=128m
-XX:MaxPermSize=128m

1 GB RAM

-Xms512m
-Xmx512m
-XX:PermSize=256m
-XX:MaxPermSize=256m

2 GB RAM

-Xms1024m
-Xmx1024m
-XX:PermSize=512m
-XX:MaxPermSize=512m

Save the file.

Now we can move onto some of the things you can do once you have eclipse open.

Those of you who use Eclipse know that it has a good error checking system. However, that robustness comes at the cost of speed. Once of the things that Eclipse does is scans through the workspace to check for errors. If you have a large workspace with a lot of projects this can take quite some time. To keep Eclipse from doing this scan each time you save a file, disable the Build Automatically option (Window>>Preferences>>Workspace). If you need error checking, you can turn it back on right before you are going to do a release.

Once of the other things you can do is close any projects that you are not using. That way Eclipse does not have to keep track of them.

Finally, we can apply the same idea to files. For each file that you have open, Eclipse has to track it an allocate memory. Close files that you are not working on and as a further step you can actually limit the number of files that Eclipse will allow you to have open in the preferences dialog (Window >> Preferences >> General >> Editors)

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

28th Aug 2008

Flex 4 Available on Adobe Open Source Site

As the title says: http://opensource.adobe.com/wiki/display/flexsdk/Gumbo

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

15th Aug 2008

Hold on a Second

You can find a lot of tween libraries for AS2 and AS3. Many of these include some sort of mechanism for delaying the start of a tween. A while back I took my own shot at this based off of another class that I found and came up with:

import mx.transitions.Tween;
class com.vfd.animation.tweens.DelayedTween extends Tween{

private var intervalID:Number
private var delay:Number = 0;

public function DelayedTween(object, property, easingFunction, start, end, duration, useSeconds, delay) {

super(object, property, easingFunction, start, end, duration, useSeconds);
this.delay = Math.abs(delay*1000);
this.setDelay();

}
private function start() {

}

private function setDelay() {
if (this.delay > 0) {
this.intervalID = setInterval(this, “startAnimation”, this.delay);
}else {
this.startAnimation();
}
}

private function startAnimation() {
clearInterval(this.intervalID);
super.start();
}

}

This was more or less a simple copy of the class I had found. I got a chance to look at this again today and realized I could simplify it a bit. I ended up with:

/**
* @author Jeremy Wischusen
* This class allows for a delay before starting the animation.
*/
import mx.transitions.Tween;
import mx.utils.Delegate;
class com.vfd.animation.tweens.DelayedTween extends Tween {
/*
Holds the number of seconds to wait before starting the animation.
*/
private var _delay:Number = 0;
/*
Instance variable holding a reference to the start function of the Tween class.
This is needed due to scoping issues when using setTimeout.
*/
private var superStart:Function;
public function DelayedTween(object, property, easingFunction, start, end, duration, useSeconds, delay) {
this.delay = delay;
/*Use the Delegate class to create a reference back to the tween start funciton
that can be used with setTimeout. */
this.superStart = Delegate.create(super, super.start);
super(object,property,easingFunction,start,end,duration,useSeconds);
}
/*Override the default start function so that the delay can be applied.*/
public function start() {
if (this._delay>0) {
_global.setTimeout(this.superStart,this._delay);
} else {
super.start();
}
}
/*Setter function for delay attribute*/
public function set delay(seconds:Number){
this._delay = Math.abs(seconds*1000);
}
}

As you can see, I reduced the number of functions, used the simpler setTimeOut and rely more on inheritance and overriding than in the previous version. I also decided to make and AS3 version.

package com.vfd.animation.tweens{
import fl.transitions.Tween;
import flash.utils.setTimeout;
/**
* @author Jeremy Wischusen
* This class allows for a delay before starting the animation.
*/
public class DelayedTween extends Tween {
/*
Holds the number of seconds to wait before starting the animation.
*/
private var _delay:Number = 0;
public function DelayedTween(object, property, easingFunction, start, end, duration, useSeconds, delay) {
this.delay = delay ;
super(object,property,easingFunction,start,end,duration,useSeconds);
}
/*Override the default start function so that the delay can be applied.*/
public override function start():void {
if (this._delay>0) {
setTimeout(super.start,this._delay);
} else {
super.start();
}
}
/*Setter function for delay attribute*/
public function set delay(seconds:Number):void {
this._delay = Math.abs(seconds*1000);
}
}
}

I have noticed that occasionally the compiler spits out:
The superconstructor must be called first in the constructor body.

If you place the super constructor before the delay variable is set, the tween just starts immediately since the variable has a default value of 0. This is what caused the need for the additional functions in the first version. While the compiler may occasionally complain (sometimes it shows the message and other times it does not), it still compiles and works.

Will be committing these to the repository on Google code sometime today.

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

12th Aug 2008

Cycling Fading Clips Using Tweens

I did this to answer a post on Flashkit and just to have something to play with. You can see the original post here. The indidividual wanted to have 3 clips fade in and out in sequence and have that sequence rotate. Here is what I came up with:

import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
/*
Create tween objects and immediately stop them so that they can be re-used.
*/
var yellowTween:Tween = new Tween (circle_mc.yellow_mc, “alpha”, None.easeInOut, 0 , 1 , 2 , true );
yellowTween.stop();
var blueTween:Tween = new Tween (circle_mc.blue_mc, “alpha”, None.easeInOut, 0 , 1 , 2 , true );
blueTween.stop();
var redTween:Tween = new Tween (circle_mc.red_mc, “alpha”, None.easeInOut, 0 , 1 , 2 , true);
redTween.stop();
/*Add an event listener to the first tween to trigger the fade in the oposite
direction. Subsequent listeners will be assigned and removed in the event
handler functions.
*/
yellowTween.addEventListener(TweenEvent.MOTION_FINISH, fadeOut);
/*
Since movie clips allow for the creation of dynamic properties (aka variables), simply create a
refence to the next tween that should be triggered directly on the clip. With
this system you could easily add aditional clips by cretaing a new tween and adding
another reference on the new clip to be tweened.
*/
circle_mc.yellow_mc.nextTween = blueTween;
circle_mc.blue_mc.nextTween = redTween;
circle_mc.red_mc.nextTween = yellowTween;
/*
Start the first tween to kick off the sequence. This should be the tween that you
added the event listener to in the previous code.
*/
yellowTween.start();

/*
Create a generic handler for the end of the fade in event. Since the TweenEvent object
holds a reference to the tween that caused the even, we can reference that tween via
the event.target property.
*/
function fadeOut(event:TweenEvent) {
/*remove the event listener that triggers this function from the tween since we have
gotten past the point of needed it and we dont want it to complete with the next part
of the sequence.
*/
event.target.removeEventListener(TweenEvent.MOTION_FINISH, fadeOut);
/*Add a new event listener that will trigger the next part of the sequence*/
event.target.addEventListener(TweenEvent.MOTION_FINISH, startNext);
/*Set the begin and finish properties of the tween object to the oposites
of those we used to create the fade in effect. I had originally tried to do
this with the built in yoyo function, but it produced un expected results.
*/
event.target.begin = 1;
event.target.finish = 0;
/*Restart the tween with the new properties, when this tween is finished,
it will trigger the new event handler we assigned in this function and
continue the sequence.
*/
event.target.start();
}
/*Now that the tween has fadded in and out, start the next tween. Again since TweenEvent
holds a reference to the tween that triggered the event, we can reference that tween.
Additionally, since the tween object holds a reference to the clip being tweened,
we can reference the properties of that clip. In this case we are interested in the
nextTween property we assigned in the previous code as this is what we will use
to start the next tween.
*/
function startNext(event:TweenEvent) {
/*Removed the event listener that triggered this function.*/
event.target.removeEventListener(TweenEvent.MOTION_FINISH, startNext);
/*
event.target is the tween that tirggred the function. obj is the property on
the tween objetc that holds a reference to the clip being tweened. hence, we can
reference the next tween to be triggered by accessing the nextTween property we created.
*/
/*
add a listener to trigger the fade out function completing the logical loop.
*/
event.target.obj.nextTween.addEventListener(TweenEvent.MOTION_FINISH, fadeOut);
/*Reset the values of the tween so that the effect is to fade in.*/
event.target.obj.nextTween.begin = 0;
event.target.obj.nextTween.finish = 1;
/*start the tween and the cycle repeate itself.*/
event.target.obj.nextTween.start();
}

After some playing with it, I was able to get it down to this:

import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
var yellowTween:Tween = new Tween (pics_mc.yellow_mc, “alpha”, None.easeInOut, 0 , 1 , 2 , true );
yellowTween.stop();
yellowTween.addEventListener(TweenEvent.MOTION_FINISH,fadeOut);

if (pics_mc.numChildren > 1) {
for (var c:int = pics_mc.numChildren-1; c>=0; c–) {
var clip:Object = pics_mc.getChildAt(c);
clip.alpha = 0;
if (c > 0) {
clip.nextClip = pics_mc.getChildAt(c-1);
} else {
clip.nextClip = pics_mc.getChildAt(pics_mc.numChildren-1);
}
trace (pics_mc.getChildAt(c).name)
trace (clip.nextClip.name)
}
}

yellowTween.start();

function fadeOut(event:TweenEvent) {
event.target.removeEventListener(TweenEvent.MOTION_FINISH, fadeOut);
event.target.addEventListener(TweenEvent.MOTION_FINISH, startNext);
event.target.begin = 1;
event.target.finish = 0;
event.target.start();
}
function startNext(event:TweenEvent) {
event.target.removeEventListener(TweenEvent.MOTION_FINISH, startNext);
event.target.addEventListener(TweenEvent.MOTION_FINISH, fadeOut);
event.target.obj = event.target.obj.nextClip;
event.target.begin = 0;
event.target.finish = 1;
event.target.start();
}

As long as all of the transitions are to be of the same length this works fine and all you would have to do to continue this would be to add additional clips to the housing clip (pics_mc) and the transition would be applied for you.

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

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 »