Archive for category ‘Actionscript’

2009
05
May
Category: Actionscript, Flex

I just realized TweenMax has been updated. Sort of anyway. First of all, if you haven’t heard of TweenMax, go read about it. It’s an amazing Actionscript library that allows you to tween things in Flash or Flex. Big deal, Adobe has classes like that build in. Wrong! This is a hell of a lot faster. Plus as an added bonus it does bezier tweening which is amazing. Back on track. TweenMax now has an optional utilities class which would allow for code hinting and strict data typing. Like I said, it is an optional class.

Here is an example of the original way:

import gs.TweenLite;
import gs.easing.*;
TweenLite.to(my_mc, 2, {x:300, y:100, ease:Elastic.easeOut, onComplete:myFunction});

And now the new/optional way to do it:

import gs.TweenLite;
import gs.utils.tween.TweenLiteVars;
import gs.easing.*;
var v:TweenLiteVars = new TweenLiteVars();
	v.addProps(x, 300, false, y, 100, true);
	v.ease = Elastic.easeOut;
	v.onComplete = myFunction;
TweenLite.to(my_mc, 2, v);
2009
05
May
Category: Actionscript, Flex

A couple weeks ago I was looking for a quick customization to the default tweens in Flex. Basically I didn’t want the Bounce to bounce as much as it was. I don’t know math well enough to make it do what I wanted so I just went with second best. Yesterday I was surfing around and I found exactly what I needed. It’s called Custom Easing Function Explorer. Which of course linked off to the Adobe docs on the same subject. Funny how I couldn’t find that when I actually needed it.

2009
05
May
Category: Actionscript, Flex

I’ve always been a big fan of Tweener. Even when it was called MC Tween I thought it was one of the best tween managers for Flash. Yesterday I found something that might compete with Tweener. It’s called TweenMax. There are three version of TweenMax. TweenLite (3k) does the basic tweens. The same as Tweener really. TweenFilterLite (6k) does what TweenLite does, plus it tweens the filters like Blur, Glow, Bevel, ColorMatrix, and DropShadow and also tweens saturation, hue, brightness, contrast, threshold, and colorization. Then there is TweenMax (8k) which includes everything the other two do a few extra things. One of the best things about it is it can do bezier tweening! How cool is that! If you go to the Family Comparison you can see the list of things each one has or doesn’t have and even see demos of them compared to other tween managers.

2009
05
May
Category: Actionscript, Flex

It’s amazing how many people still don’t know about …rest. On the other hand I think I have only played with it but never actually used it. Basically what …rest does it allows you to pass, or not pass, parameters to a function. …rest parameters are passed just like all variables but in the function it will be an Array. Here is an example:


function myFunction(required:Number, ...optionalArgs):void
{
trace(required); // 1
trace(optionalArgs); // [2, 3, 4]
}
myFunction(1, 2, 3, 4);

The same functionality can be achieved a couple other ways. This next example you set a default value for each variables you pass. But this isn’t an undetermined number of arguments.


function myFunction(option1:Number=0, option2:Number=null):void
{
trace(option1); // 1
trace(option2); // null
}
myFunction(1);

Another way is similar to the way jQuery does it plugins. I don’t have an example of it but you pass all of your variables that you want in an object to the function. You can have any number of items in the object. Inside the function you have default values in case the variables aren’t passed. Then the variables that were passed overwrite the default values.

2009
04
May
Category: Actionscript, Flex, Links

I found a great resource today called the ActionScript Error Repository. Let’s say you are working in Flash, Flex, or AIR and you get a fun error message: Error #2032: Stream Error. You can search for the error code and it will explain the cause and how to fix it. It will give an example of bad that that will cause a similar error and it will also give you an example of good code that you can copy/paste.

2008
27
Jul
Category: Actionscript, Flex
Tags: ,

Let’s say you are loading in an image. The image is a little to big to fit in the area it is supposed to go in or maybe too small so you have to scale it up a little. The problem is, if you scale it, it will end up looking absolutely horrible. All is not lost. Adobe has an article by Ben Longoria on creating a component called SmoothImage which basically takes your image and once it is loaded in, it casts it as a bitmap in order to apply bitmap smoothing to it. Ok, granted, the article is a little dated. It was created April 6, 2007. It can be used as a basis for your own custom MXML component. Maybe you are the type of person that likes to use Actionscript components instead of MXML components. This basically does the same thing. Once the image is loaded in, it calls this function which casts it as a bitmap and applies smoothing.

[Updated July 28, 2008] Here is an example of an Actionscript classes bases example.