MC Tween: it saves the world.™

Home | Using MC Tween | Documentation | Animation Types | Downloads | Examples | Extensions | Author & Disclaimer | Links

Special notice! While MC Tween is a nice extension and it will continue to work for AS1 and AS2 until the end of time, it is my duty to inform all citizens that I have switched the focus from further development on MC Tween to a new AS2 and AS3 extension, a real Class this time, called "caurina.transitions.Tweener" (or just Tweener). Tweener doesn't have as many features as MC Tween yet (for example, it doesn't have native filter tweens), and the documentation isn't 100% done, but it features a complete, more solid redesign with a few additional syntax features that were impossible to achieve with MC Tween. And it works the same for AS2 (including Flash Lite 2+) and AS3.

So, if you use MC Tween, or you're thinking about using it, I'd like to suggest you try Tweener instead. It follows all the principles of simplicity I tried to feature on MC Tween, but with a more powerful syntax. Tweener download, examples and documentation are available on Tweener's page. You can read more about this change on this blog post.

Thank you for your attention and sorry for this ugly box. And don't worry, this website will not be deleted or anything.

Notice for October 2008: also note that, if you are still interested in MC Tween and don't want to use class-based AS2 or AS3 solutions, Larry Benedict has taken the matter into his hands and updated MC Tween with some filter features that are not available in the latest version. You can read more about it (and download his version) here or here.

AS2 usage notes

ActionScript 2.0 (or AS2) is a more OOP-driven version of Actionscript. It allows you to use external classes, and to write code in a more stric way - with variable typing, and using case sensitive code. In a certain way, you can compare AS1 to JavaScript - a sloopy scripting language - and AS2 to Java. In AS2, you can't create variables out of thin air - it will throw an error. I the same vein, you can't assign, say, String data to a Number var - it won't compile properly.

Even though AS2 is just a different way of writing the same thing (AS2 gets compiled back to AS1), AS2 is a great tool when creating code. It allows you to catch typing errors, and forces you to follow some basic rules when coding - rules that you can benefit from.

However, many of the AS2 features go directly against the prototype nature of AS1. In AS1, you could extend any Class - like the MovieClip, or the Array classes - adding new methods or functions to them. And that is exactly what MC Tween does - it adds new methods and functions to the MovieClip, TextField, and Sound classes. However, such approach goes against the more strict OOP rules - used by AS2 - because you aren't supposed to extend an already existing class. So, if you try to use an MC Tween method (like MovieClip.tween()) under a properly typed object on AS2, you will get an error like this:

**Error** Scene=main, layer=actions, frame=5:Line 100: There is no method with the name 'tween'.
myMovie.tween("_x", 0, 1, "linear");

In AS2, if you need special functionality, the usual ways to get them are to create new classes that are extensions to the existing one - say, a MovieClipWithTween class - or a new, static class (a class that doesn't create objects, but that has its own methods and functions) to control tweening - like, say, a Tweener class.

However, this doesn't mean prototype-based extensions can't be used anymore. Since AS2 is just a set of rules for compiling, they can be circumvented with little to no collateral damage - after all, again, AS2 is just AS1 after compilation. So, here's a few solutions you can take if you're having problems compiling or using MC Tween (or any other prototype-based extension) under AS2.

Keep in mind, however, that many times you will not have a problem with using MC Tween under AS2. Problems arise when you are using properly typed variables, variables inside an external class, etc. On such cases, if the compiler is giving you an error, then you have to look into this solutions. Also remember these examples serve for all tweenable classes - MovieClip, TextField, and Sound objects.

Solution 1: Upcast your objects (recommended)

Upcasting is the technique of telling the compiler that a certain object - say, a MovieClip - must behave like a more low-level class, a class that it extends - like the Object class. This prevents the compiler from checking if you're calling methods or functions that really exist; since the Object class is a more abstract class, it's as if anything goes. To upcast an object, you just wrap him with the new class name - on this case, Object().

For example, this will give you an error:

var ss:Sound = new Sound (this);
ss.attachSound("myMusic");
ss.start(0,100); ss.volumeTo(100, 1);

This won't:

var ss:Sound = new Sound (this);
ss.attachSound("myMusic");
ss.start(0,100); Object(ss).volumeTo(100, 1);

On the same way, you might have problems with function parameters, as this will give you a compilation error:

this.mute = function(ss:Sound): Void {
    ss.volumeTo(0, 1);
};

This, however, will work flawlessly:

this.mute = function(ss:Sound): Void {
    Object(ss).volumeTo(0, 1);
};

Pros of this method: straightforward; you will still have the benefit of type checking everywhere else.

Cons of this method: you have to wrap your typed objects everywhere you want to do a MC Tween call.

Solution 2: Do not give your objects a proper type

Type checking on compilation only occurs on objects if Flash knows their types. If you use an abstract object - which can be of any type - the compiler won't trigger any kind of type checking and you can use prototype based extensions as easy as always. This is similar to coding in AS1.

For example, this (which gives an error):

var ss:Sound = new Sound (this);
ss.attachSound("myMusic");
ss.start(0,100); ss.volumeTo(100, 1);

Can be written as this, without a declared data type:

var ss = new Sound (this);
ss.attachSound("myMusic");
ss.start(0,100); ss.volumeTo(100, 1);

And again, the same applies to functions - if you omit the parameter type, there will be no type checking. This gives you an error:

this.mute = function(ss:Sound): Void {
    ss.volumeTo(0, 1);
};

This doesn't:

this.mute = function(ss): Void {
    ss.volumeTo(0, 1);
};

Pros of this method: straightforward; you can write as if you are writing AS1 code.

Cons of this method: without data typing, many of the useful checks done during compilation are gone, defeating the purpose of using AS2.

Solution 3: Editing declaration files

Type checking occurs on existing variables because Flash "knows" which methods and functions each of the classes are supposed to have. So if you try calling MovieClip.tween(), he will automatically know that doesn't exist (even though it does) and throw you an error.

Even though most of those methods are built inside the player, Flash stores an external file that lists all functions the built-in classes have - so, when compiling, Flash will know what's allowed and what's not. The interesting part is that you can edit this file and Flash will now recognize all methods you add as being native methods of that class.

This doesn't mean it will automatically include MC Tween functionality on all MovieClip, TextField, and Sound objects! It will just make it think that these methods are original methods of that class and won't give you compilation errors. You will still have to #include the MC Tween AS file for it to work.

This is not a recommended method at all. Because of this, I'll just tell you how it's done, but not provide the modified files themselves.

The method files are located on this folder:

[Your Flash installation dir]\[Your language]\First Run\Classes

Flash MX 2004 files will be on this folder. Flash 8 files will be under the /FP7 and /FP8 folders. To add MC Tween methods to the compilation directives, the files MovieClip.as, TextField.as and Sound.as have to be edited, and MC Tween function declarations have to be added to this file. Again, I won't provide the files of the text because this is not something I'd recommend, but keep in mind it's possible.

Pros of this method: clean when writing actionscript.

Cons of this method: dirty modifications to the original class declaration; you have to do that on computers that will compile the file.

MC Tween· Zeh Fernando, 2003-2006 · Proudly hosted at DreamHost · Disclaimer