Archive for September, 2007

Book review: ActionScript 3.0 Cookbook

Not so long ago I bought the book ActionScript 3.0 Cookbook by Joey Lott, Darron Schall & Keith Peters, from O’Reilly. I’m a big fan of O’Reilly’s book; I got one for every computer language I learned. Usually I get the Definitive guide kinda book, but this time I decided to get a cookbook since you see these a lot and I never really stopped to see what it was.

In general it’s a pretty good book, for what it covers, it’s really well explained.¬† I found it’s a good book to read fast; you just go over the pages quickly and look at the examples¬† and it will give you ideas about what you can do in ActionScript 3 and how you should do it. For the most part it is targeted to a wide audience, novice to advanced programmers. That’s what I found not so useful about it. About 50% of the book is on really basic topics like: how to trace a message, how to add element to an array, etc. Mostly everything before Chapter 6 is really trivial. There is also a whole chapters about Date and Time. I found strange that in the Programmatic Animation chapter, they wouldn’t even speak about the tweening and easing classes.

The really good thing about this book is the chapter about the display list. It is something new to flash and they really take the time to explain it well.

All in all, it’s a good book; I don’t think that you can’t live without it, but it’s definitely nice to have around when you program.

, , ,

No Comments


useHandCursor and Sprites in ActionScript 3

Here is another thing I was trying to do today, but I couldn’t find an answer on the net. I was quite simple actually; I was just wanting to make the mouse display the hand cursor when it rolled over some Sprites. Since Sprites don’t have timelines, you save memory in comparison to MovieClips. That’s one of the major change in ActionScript 3 and it gives even more meaning to doing your animations using code.

So one of the things you might want to do is add some mouse functionality to your Sprites and let the user know about it by displaying the hand cursor. In ActionScript 2, that was quite easy. You just had to implement a mouse event function like onRelease, onRollover etc and that was it. No need to specify it, the cursor would automatically change to a hand cursor. In ActionScript there are no such functions anymore, you have to make a listener to catch the events and then your event handler functions. So you have to specify when you want the mouse cursor to display the hand.

Now that looks easy, just turn the useHandCursor of the Sprite to true. Yes, that’s one part of it, but there is another step that is not so obvious. You have to also set the buttonMode property of the Sprite to true (in which case you don’t have to set the other property). Here is some example code for it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package {
  import flash.display.Sprite;
  import flash.events.*;
  public class thumb extends Sprite{
    public function thumb(image:String, X:int, Y:int)
    {
      x = X;
      y = Y;
      buttonMode = true;
      addEventListener(MouseEvent.MOUSE_UP, handleMouseUp);
    }
    function handleMouseUp(event:Event){
      //your code here (simular to onRelease in actionScript 2)
    }
  }
}

I hope it saved you the hour it took me to find out.

, ,

12 Comments


Mouse Wheel problems and no answer

My search of the day is about the mouse wheel. So I’m making this scrollbar Class and to make a full fledge scrollbar you need to make it work with the Mouse Wheel. Ok, this part is not so bad, I look around a bit and I find this:

1
2
3
4
5
6
7
8
9
10
11
12
13
var mouseListener:Object = new Object();
mouseListener.onMouseWheel = function(wheelNum:Number)
{
if (wheelNum > 0)//rolling wheel toward the screen
{
//your code
}
else if (wheelNum < 0)//rolling wheel away from the screen
{
//your code
}
}
Mouse.addListener(mouseListener);

This works out pretty well when testing inside the Flash authoring tool. The interesting part of this code it the Mouse.addListener part because in ActionScript 2, there is no mouseWheel event on MovieClips, you have to use the global object Mouse to catch the mouse wheel. This can cause trouble because it won’t only catch the mouse wheel when the mouse is over the MovieClip, but at large, when the mouse is over the entire flash movie. You have to tweak it to make it work this way. I think this is resolved in ActionScript 3; most of the mouse events are renamed for consistency and there is a mouseWheel event on MovieClips.

My trouble was that when I tried my movie in a browser, sometimes, the mouse wheel didn’t work. At first I was thinking it was because my SWF that had the mouse listener in it was loaded in another SWF. When I make a website, I most of the time make an external preloader; this way it will preload the MovieClips I export for ActionScript. I found out that the trouble was actually coming from the SWFObject. When I was using SWFObject in my HTML, the mouse wheel wouldn’t work in FireFox and Opera (it works fine in Explorer). I looked around a bit to find other people with the same problem and found none… So I did some testing on my own.

At first I tried getting the new version of SWFObject here but that didn’t do it. I also tried to use the fix to make the mouse wheel work in Flash when you use Mac OS X that can be found here. But that didn’t do it. My last option was to use the new technique from the makers of SWFObject and UFO: SWFFix. There it was, the answer to my problem. Trouble is, it is only in alpha stage and its not a stable release, but in my case it worked real fine. I will check for new version often to be the more stable as possible, but for now I am pleased with this option.

I have another point I want to make, I wanted to start deep liking my site to enable more browser options (back, foward, history) and the script I had found was based on SWFObject, so I can’t use it in this case.

, , , ,

5 Comments


Using the Fuse kit for animation versus using the Tween Classes

Most of what I will write about is interesting stuff I found while searching for something. When searching for the tween classes in Flash CS3 I stumble two times on people speaking about the fuse kit for animation. I have as a motto to check out things that I hear about twice, so that the next time it comes up, I know what people are talking about. In this case this could even be helpful for my job, so I go and check it out.

The fuse kit are some ActionScript2 classes that simplify that syntax of doing animation using ActionScript. It has 3 parts; one is the Zigo Engine which handles the tweening. It can be used as a standalone. The second part is Fuse itself, which are sequencing classes that helps you organize your tween in time. The last part is FMP which permits you to use filters with Fuse.

This all looks pretty good, with it you can do tweens in sequence as well as in parallel. I say to myself, that is fantastic, I will be able to get rid of the setTimeout in my code and my ActionScript will be simpler to understand.

There is only one catch; The Zigo engine in itself adds to your SWF 34k, Fuse: 2k and FMP: 1k for a grand total of 37k. So it rules out the possibility to use it in banners and such. When I make a flash movie, I want it to be as small as possible so the idea of starting my SWFs at 37k doesn’t make me happy. Also you can’t use the Fuse kit to do roll overs; I do all my rollovers in actionscript so I would have to import the tween classes from Adobe too to add another 2k. For me it just doesn’t cut it; if my website as more than one SWF it’s 39k I have to add each time.

So in the end, the Fuse kit looked pretty good, but its advantages don’t match up with its disadvantages…

, , ,

No Comments


Flash IDE, FlashDevelop, SE|PY

While searching around for answers, I stumbled a couple of time on developers who didn’t use the actionScript editor that comes with Flash. As a matter of fact, before Flash CS3, the default editor wasn’t packed with options and was kinda simplistic. I was working on a project where I was up to 1000 lines of code so I said to myself, that’s right I need something that has more options. So here are the options I found:

SE|PY: It’s the first one I found, I guess it’s been around the longest. It’s kinda cool, and really easy to customize. It was made by Alessandro Crugnola from http://www.sephiroth.it/ . If you’ve done Flash for some time, you surely ended up on this site one day. This is a good interface, but it has two major down sides: it looks kinda old and it is not in development anymore.

FlashDevelop: I think FlashDevelop is the most promising interface out there. It looks great and has most of the feature that SE|PY has. It’s kinda hard to change the syntax color of the code, but that’s mostly it. It has a great structure for adding plugin so it might become really good in time. Another point I didn’t like was that for help about actionScript code it sends you to adobe liveDocs on the web which is awfully slow.

Flash IDE: This is the default interface that comes with Flash. Up to Flash 8 I would say that you need another interface if you do a lot of actionScript coding. The thing is, that in Flash CS3 Adobe really put some time on the ActionScript editor and made it the better than even FlashDevelop. It now has code folding, and can fold mostly anywhere, not just functions (like in FlashDevelop). Help is easy and fast and it is integrated with the rest of the Flash interface.

So there it is, my review of the ActionScrip editors out there. My big winner is the Flash CS3 editor, but you have to watch closely for FlashDevelop development because it might become really interesting.

, ,

4 Comments


ActionScript 3 Tween Classes

I was reading the book ActionScript 3 cookbook from O’Reilly (very good book by the way) and I wanted to get my hands dirty. I have never coded in ActionScript 3 before and where i work we still use Flash 8 because it’s what most people have. So there I was wanting to do basic stuff, regular animation using the tween classes from Flash, but at first I couldn’t find them. Searched a bit and found all sort of post saying they didn’t exist anymore, or that you had to use classes from Flex in order to use them. I finally found them after some time. So let me spare you that effort. Here are the tweening classes from flash CS3.

1
2
import fl.transitions.Tween;
import fl.transitions.easing.*;

and they still work the same way using this syntax:

1
var myTween:Tween = new Tween(myObject, "x", Elastic.easeOut, 0, 300, 3, true);

The only difference is with the “x” where it used to be “_x” because ActionScript 3 dropped the underscore before key properties.

, ,

1 Comment


Where this all started

zedia.net used to be the website for a company I had with two friends. We did good for a while made some websites, learned the ropes, made some money but when we finished school, we all went our way. Still it took us so much time to find a name that we all liked for the company and the web address that I didn’t want to just throw it away. So I’m going to use it for my blog. I didn’t think I would ever make a blog, but recently I have been looking around for questions about Adobe Flash and I have had a hard time finding the answer I wanted. So mostly this blog will be about my research in the ActionScript domain and mostly everything I find interesting.

For now I will use the wordPress platform to blog until I find something better. for now it serves all my needs. Also several changes will appear on the page as I tweak the interface. I don’t know how often I will update this blog, but I guess we will see…

, ,

No Comments