negush blog

Flash, ActionScript and stuff…

(Didn’t know what other title to give it, so this is what I came up with)
I came upon a strange problem a few days ago. I was trying to create a simple function that would take a String value and return that value in a simple data type (String, Boolean, Number, int or uint), based on a parameter specifying the type to return. So the easiest way was to use a switch test for all five of the types and return the value accordingly. When trying to return a Number, int or uint data type, I wanted to use a try..catch statement, just for making sure that the function would not break when using the parseFloat() and parseInt() functions. So, my function looked like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function getValue(value:String, type:String):* {
 
	switch(type) {
 
		case "String": {
			return value;
		}break;
 
		case "Boolean": {
			return (value == "true");
		}break;
 
		case "Number": {
			try {
				return parseFloat(value);
			}
			catch(e:Error) {
				return NaN;
			}
		}break;
 
		case "int": {
			try {
				return parseInt(value);
			}
			catch(e:Error) {
				return NaN;
			}
		}break;
 
		case "uint": {
			try {
				var num3:int = parseInt(value);
				if (num3 >= 0) return num3;
				else return NaN;
			}
			catch(e:Error) {
				return NaN;
			}
		}break;
 
	}
 
	return null;
}

With the function in this form, it seems that the player simply breaks down and displays a whole bunch of error messages in the Output panel. Besides those, it also displayed the entire application into compiled code, looking something like this:


verify test_switch_fla::MainTimeline/getValue()
exception[0] from=42 to=52 target=56 type=Error name=e
exception[1] from=78 to=88 target=92 type=Error name=e
exception[2] from=117 to=153 target=157 type=Error name=e
stack:
scope: [global Object$ flash.events::EventDispatcher$ flash.display::DisplayObject$ flash.display::InteractiveObject$ flash.display::DisplayObjectContainer$ flash.display::Sprite$ flash.display::MovieClip$ test_switch_fla::MainTimeline$]
locals: test_switch_fla::MainTimeline String? String? * *
0:getlocal0
stack: test_switch_fla::MainTimeline
scope: [global Object$ flash.events::EventDispatcher$ flash.display::DisplayObject$ flash.display::InteractiveObject$ flash.display::DisplayObjectContainer$ flash.display::Sprite$ flash.display::MovieClip$ test_switch_fla::MainTimeline$]
locals: test_switch_fla::MainTimeline String? String? * *

It also had a few dozen lines more of this kind. Pretty strange problem, I told myself and tried to find out why was this happening. It turns out the problem were those return NaN statements from the try..catch blocks. If I would only use the return statement, without the value to return, that would turn out to be ok (except that the function would still have to return a value and would not be correct from the application point of view).

Also, when testing the try..catch block separately, not inside the switch statement, it seems that there is no problem when the return statement is found in the catch part of the block, including the value to return. So the next code throws no errors:

1
2
3
4
5
6
7
8
9
10
11
function testing():Number {
	try {
		var test:Number = parseFloat("kdhk");
		return test;
	}
	catch(e:Error) {
		trace("catch");
		return NaN;
	}
	return NaN;
}

In conclusion, do not place return value statements in the catch blocks if those blocks are placed in switch statements. Anyway, in my case, there’s no need for the try..catch blocks, since parseFloat() and parseInt() always return a value (NaN if the source string cannot be converted), so it makes no sense using the try..catch block. After reviewing my code, here is the simple conversion function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function getValue(value:String, type:String):* {
 
	switch(type) {
 
		case "String": {
			return value;
		}break;
 
		case "Boolean": {
			return (value == "true");
		}break;
 
		case "Number": {
			return parseFloat(value);
		}break;
 
		case "int": {
			return parseInt(value);
		}break;
 
		case "uint": {
			var num3:int = parseInt(value);
			if (num3 >= 0) return num3;
			else return NaN;
		}break;
 
	}
 
	return null;
}
 
 
trace(getValue("test", "String"), getValue("test", "Boolean"), getValue("test", "Number"));
//    test false NaN
trace(getValue("12.34", "String"), getValue("12.34", "Boolean"), getValue("12.34", "Number"));
//    12.34 false 12.34
trace(getValue("-23", "Number"), getValue("-23", "int"), getValue("-23", "uint"));
//    -23 -23 NaN
March-12-08

Flash Text Effects – How Easy It Is ?

posted by negush

There are a few ways to create text effects using Flash, like alpha or blur animations, color changing, text scaling or moving text and these are relatively easy to do. But what happens if you’ve seen some fancy text effect on a site or even in a video clip, perhaps in a movie, and you want that exact effect in your Flash banner, presentation or site ? It is highly unlikely that the effect was made with Flash. Chances are it was made with some professional tool for video editing.

If you want to have that same effect replicated in Flash, that means you’re going to work for the next few nights and write a lot of code to get there. Yes… if you’re a Flash and ActionScript pro… But what if you’re a rookie… Maybe you’ve never written code before. What then ?

Then, you should use this great tool developed by us at Jumpeye Creative Media. It’s called TxEff. This is a Flash CS3 component (only works with ActionScript 3.0) which you can use to create amazing text effects in Flash, literally in a few minutes, with just a few mouse clicks and a few parameter settings. That’s how easy has become creating Flash text effects. The animation below took me 15 minutes to complete (including testing more parameters to get the effect I wanted and consulting the help pages to get more info on some parameters).

Another great thing about it is that there is a free version of the component, that comes with three patterns embedded into it. You can use these patterns to create a large number of effects, number limited only by your imagination. You can download the component from JumpeyeComponents’ site but you’ll need an account for that (if you don’t have one, go ahead an create it). On the same site, you have access to several tutorials to get you started, the component’s help pages and documentation on all the patterns and their presets. These patterns are actually extensions of the component, so you’ll need both the component and the pattern into the Library, to create an effect. JumpeyeComponents also has a Knowledge Base, containing solutions to a few common questions regarding TxEff.

Besides all these, the component’s site (www.txeff.com) is actually a large effects database, created by all the people visiting the site. If you like an effect there, you can easily import it into your project (just remember to have that pattern into your Library).

Let me give you a piece of advice: before starting to work with TxEff, try to go through the documentation. The component is quite complex, even though it is easy to use, and has a few limitations and requirements. Also try to check out some of the tutorials to get a better idea of what TxEff can do. If you’re having problems with integrating the component, you should read the documentation first or check out the knowledge base… Chances are that you’ll find the answer to your problem there. If not… JumpeyeComponents support team will happily help you out.

Download source files