Posts Tagged Actionscrip 3
How to use interface in ActionScript 3
Posted by zedia.net in ActionScript 3 on January 1st, 2008
There are a lot of good ActionScript 3 books out there, but in most of them all the examples about inheritance, composition, interface, polymorphism and more complex object oriented principles are done using data classes. It’s good to explain the principles, but when you are ready to code some actual classes in Flash, some problems start to arise. Most of my problems come from the fact that 90% of the time I am coding classes that are a visual representation of something. So these classes extends the Sprite or MovieClip class.
So I was coding this game class where I have multiple kind of monsters but I want to use the same functions without checking what kind of monster it is. This is a case where polymorphism comes in handy. The thing is I didn’t do my classes of monster using inheritance (which maybe I should have done), so in order to use polymorphism, I have to create an interface with the public methods common to all my monster classes. So I open the Colin Moock book and start looking at how to code interfaces. Here is a list of quick facts that will help you while doing so.
- You have to list all public methods that will be common for the classes that implements this interface;
- You do so by writing the definition of the function, its name, its parameters and its return type;
- You don’t have to open and close curly braces after the method definition
- You don’t specify if the method is private, public or protected (that’s kind of obvious but I did that mistake)
- interface can only extend other interfaces
- a class can implement more than one interface
So here is an example of an interface in As3:
package com.mutantfarm.monster{ public interface IMonster { function getShot(damage:uint):void; function getCanShoot():Boolean; } }
Here is how my visual class implements this interface while also extending the MovieClip class:
public class spriteMouton extends MovieClip implements IMonster{
It is important that you put the extend keyword before the implement keyword.
So most of what I just wrote about was details about interfaces, but when you start coding, all these details are important to know.
Here are two more article I wrote about interfaces:
The best snow effect in ActionScript 3
Posted by zedia.net in ActionScript 3 on December 15th, 2007
During the last days I’ve been doing Christmas cards for different clients for the agency I work for. One of those cards needed some snow in the background so I searched for different scripts in as3 to make a snow storm. I found 3 of those scripts and I will review them in this post.
The first script is snow effect with wind from neatFilm. It looked nice on the website, but when I tried to integrate it in my movie nothing seemed to work quite right. The code seems really strange, there are a lot of “this” keyword used for nothing and an internal SnowFlake class that you don’t know why it’s internal…. I wouldn’t advise using this class.
The second script is a script I found today. It’s a script made by Seb Lee-Delisle in 15 minutes. Well this guy must be really good if he made that in 15 minutes because it works pretty nicely. It doesn’t use too much CPU and I only had to tweak it a bit to make it work as a class that I could import easily.
The last script is made by the dude at pixelfumes. This guy released this code a long time ago and its been used on a lot of sites and even TV advertisements. The trouble is that this snow storm class is really heavy on the CPU, if you have 2 windows running one of your movie each, it’s going to run very slowly. Also even with some evident tweaking made to the code it stays heavy on the CPU.
So you can guess that I was pretty happy when I found the galaxy goo script today. It’s really the best one and next week I’ll show you what I have done with it.
Using fl.* packages in Flex and more
Slow days at work means I get to experiment and search the web for new ways to develop. I did a lot of research today on Flex until I stumbled on this presentation on the beedigital blog. It’s a very nice presentation on how to integrate Flash and Flex in your workflow. That’s exactly what I wanted. After see it I tried to do some test projects in Flex. Most of the time I do every thing in ActionScript so I thought this wouldn’t be too difficult. The trouble is that most of the time I also use the Tween and Easing classes from Flash. These classes come in the fl.* package and this package does not compile in Flex. I searched a bit how I could make these classes compile but I only found complicated methods of doing so. I tired also to use the Tween classes from Flex, but in order to use them you have also to include the Flex framework which adds 100k to your project. My simple solution to this problem; using Tweener for my tweens. Tweener only adds 10k to a swf file compared to the fuse engine (which is not in AS3 yet). It’s not so bad, it’s only a 8k difference to the Flash Tween classes (2k). Also using it a bit, I might have misjudged Tweener a bit because it works very well. I might in the future redo some example using Tweener instead of the Tween classes.
I went on the blog of Samuel Asher Rivell, the author of the presentation I spoke of earlier, and found some other interesting things. First there is the Montreal Game Summit that’s going to be held on November 27th and 28th. I live in Montreal so I’d be pretty happy to go there, at least on the first day. It has some interesting conferences about Flash that I’d like to see especially the one given by Samuel Asher Rivell on Advertgames. The second nice thing I found on his blog is the powerpoint presentation of one of the conference he gave on blitting. I had seen the technique some time on the web but never knowing what it was or how to do it. His presentation is a good introduction to it and I’d be really interested in hearing his speech about it. There might be more on blitting on this blog since it looks really promising.
SEO and Flash part 2
In the previous article I said my tutorial about search engine optimization was going to be in 2 parts, well it’s going to be in 3 parts. In this part, I’ll explain the brute force way of making what we did the last time even better and I’ll explain the motivation behind it.
Remember that in part 1 I said that one of the most important factor in search engine optimization was what is inside the title tag. Well the easy way of making you flash website be present in search engines didn’t really optimize that factor; we used it a bit but not to its full potential. Also there is something else I didn’t speak about; the description meta tag. This tag is not a factor to be well ranked in search engine, but it can definitely be a reason why the user will click on your link on the Google page or any search engine’s page. The description meta tag define the paragraph of text that will be displayed below the link in the search engine search result page. Having a good and precise description can really help get users to your website. Lastly, if somebody searched for an expression that is present in your flash website but it is really far in and not that easy to find, in our previous method, the user will have to search trough your site to find it and might leave before even finding it.
Ok, so the previous method was that we dumped all the text present in the swf file in the html page embedding it. This was fine, but not really optimal as I have explained. Going from there, what the brute force is all about is dividing all the content we dumped in the first method into different html pages. For each section in the flash website, we make a page for it in Html and we embed the same swf in all pages. There are 3 particularities you have to add to make this work.
First, in the embedding method using SWFObject, you have to pass a variable the swf file telling it what page it is on. You can do it in this way:
<script type=“text/javascript” src=“swfobject.js”></script>
<script type=“text/javascript”>
var flashvars = {
page : "WRITEYOURPAGEHERE"
}; swfobject.embedSWF(“myContent.swf”, “myContent”, “300″, “120″, “9.0.0″, "expressInstall.swf", flashvars);
</script>
So now the swf files knows what page it is on, but it has to do something with it. When the flash loads it has to check in ActionScript for the variable that was passed to it in our case _root.page and display the good content section according to it.
The last thing you have to do is in the alternative content, make a link menu that links all html pages you created. This menu has to be in every html page of your site. You have to do this so that search engines spiders can access all your pages and index them.
What we did with this method is create multiples entry pages to your flash website instead of just one. Also this enables us to give a different title and description to each page which optimize those factors. With all this said, I can now explain why I call this the brute force method; this is not yet the best method to optimize your website for search engines. It will give you the same results as the next method, but will require more time as is harder to maintain since when you make a change in content in the flash file, you also have to do the same modification in the html page. The good point is that this method doesn’t require any server side scripting like php or asp.
New FlashDevelop beta version
Posted by zedia.net in FlashDevelop on November 1st, 2007
This is just to tell you that there is a new version of the beta of FlashDevelop 3(ActionScript editor). There wasn’t any change since august 25th. I didn’t try it yet, but I soon will, it can only be better.


