Modern addiction: ActionScript 3.0 Chit chat about AS 3.0, OO concepts, and Flash in general…

25Jul/091

Getting fresh data from database

2702418661_28a44ea538

Problem

Problem is that some browsers won't refresh data got from database. They cache query results. Example:

var url:String = "http://www.example.com/get_data.php";
var req:URLRequest = new URLRequest( url );
var loader:URLLoader = new URLLoader();
loader.load( req );

So with this you can load results from php document. But when you ask for results again, some browsers (I noticed IE) will cache results and you will get same results. Refreshing the page and loading your application again will help. But you don't want user to refresh page, don't you?

Solution

Solution is pretty simple. In order to get new result you must confuse browser. You can confuse it by giving it new url to load. So, on our original url we will give it some meaningless sufix which won't do anything other than generate new url.

url += "?randomVar=" + Math.random();

Your new url will look like this now:

http://www.example.com/get_data.php?randomVar=0.8319580480456352

This way on every refresh you get different number as sufix, making your url unique.

Finally your code should be:

var url:String = "http://www.example.com/get_data.php";
url += "?randomVar=" + Math.random();
var req:URLRequest = new URLRequest( url );
var loader:URLLoader = new URLLoader();
loader.load( req );
Tagged as: , , , , 1 Comment
28May/092

Make yourself some ASDoc!

asdoc

Commenting evolution...

When I started out with programming I looked at commenting my code as unnecessary job. But back then, I worked with small programs. Then I was in a situation when I couldn't remember what classes are for what, and what some methods are doing. So I started commenting my code with simple line comments (//) or block comments (/**/). That was good enough for couple of years. Code was good, my methods, variables and classes were labeled. I wrote myself some kind of standard for code commenting. After that I wanted to have some documentation for my code. Then I opened Excel and wrote 3 columns. One was for methods name, second was for class name, and third was for method description. Now, I'm in stage when I don't have time or the motivation for double writing comments. That led me to discovery of ASDoc.

What is ASDoc?

Most simple explanation is that it is a tool for making documentation of your comments which are written in specific formatting. You comment your code with some explanation, some tags, and ASDoc will generate html documentation.

ASDoc formatting and tags


Formatting

It is really simple to format your comments for ASDoc. It's basically like writing block comments except you have one character more. One simple example is this:

/**
* Your description goes here.
*
* @tag Tag description goes here.
*/

Like I said before, your comments consist of explanation and tags. Important thing is that your first sentence have to describe your complete code (method, class, function or variable). I'll explain this on example. Let's say you commented your public function. That function will be visible in your documentation. Under your class there will be list of function on top. In that list you will find your function and short explanation which is exactly your first sentence. Sentence ends with period followed by  delimiter (space, tab, line break).

You can have as much sentences as you like, and all of them will show in detailed description of the code you commented.

Note:
Notice asterisk (*) and one white space is before every new line. It is common practice to put it like this. It will make your code more readable for you and needed for ASDoc tool to parse your comment.
Also I like to save some space and organize things, so when not needed, I write one line comments like this:

/**My one line description*/

Tags

Except describing your part of code, you can give it some "special abilities", called tags. Tags will put your tag explanation in special place and have it specially formatted in generated documentation. That will make your documentation more readable and more structured.

Note:
In section below, I gave a link to what Adobe calls "complete list of ASDoc tags". It isn't complete list! The best way to find tags which you want is to go to Adobe documentation, find some piece of documentation you like, then go to Flash classes (where you installed Flash) and open that class in which you found that piece of documentation, and read out that tag and it's formatting.

Read more

Creating ASDoc comments
Documenting ActionScript elements
Complete list of tags

FlashDevelop integration

If you don't know what FlashDevelop is, check out FlashDevelop - essential developing environment.
Since I like working with FlashDevelop, I wanted to integrate documentation generation in it.

First you have to download and install FlexSDK if you don't have it. This is needed since ASDoc is now part of Flex SDK.

Next you have to configure your FlashDevelop to connect to ASDoc in FlexSDK. Read tutorial here.
(don't forget to remove line breaks and " in tag)

That's it. Now when you are done writing your comments, just select ASDOC button from toolbar and your documentation is generated.

Note:
asdoc_folder_structureOne other thing is that you have to have proper folder structure for generating you documentation. My folder structure is on the picture. This is needed because when you choose to generate ASDoc it will create separate folder in which it will store all documents needed for your documentation. In src I put my source code, in deploy goes final product, and in root is my FD file. Then when I click on ASDOC button  to generate documentation, it will create doc folder in the same directory as your FD file. If you follow their tutorial and input their code in Toolbar.xml, it states path to your source code folder. I find this structure as the best way of keeping your files neatly organised. If you still choose to have your own structure, just replace -doc-sources path in Toolbar.xml.

Final thought

Well ASDoc made my life easier. Now when I work on a project, I have complete description of my classes in one place. It really ensures you if you need to return to some project after a while.

26May/090

FlashDevelop – essential developing environment

Overview

FlashDevelop is awesome tool which is used as developing environment. I've been using it for a great deal of time now. It has nice organised and intuitive interface, it's easy to set up, and the best of all, it gives you ton of features that you don't have implemented in Flash. I'm talking here about Flash CS3 since I possess it. Some of my best features I'll be covering in this article.

With nice looking environment and tons of features you would expect some price. But fortunately for us developers, FlashDevelop is free. If you want, you can support the project and donate through PayPal (they deserve it).

Features

Like I said, there are a lot of features which are really useful when writing your code. I'll cover only some of them. Complete list of features you can find in FD (FlashDevelop) tour section: list of features

1. Code completion

This one is really time saver! I've been working with C# for a while, and I loved it's IntelliSense. That is really one thing that Flash misses and I, as developer, miss even more.

In Flash you have a little bit of code completion functionality. As I noticed, code completion only shows when you do import classes or when you name your variable with sufix txt, mc and btn (i.e. myTextField_txt). If you miss one letter when writing your code code completion in Flash will close, which is not the case in FD (it will stay open and offer possibilities).

Great thing is that when you import classes, you can write only final class name, and not whole package to get to final class which you want to import like in Flash.

Beside having offered object name in code completion, it also includes graphical presentation of function, getter/setter, private and public variable, etc. (simple icon which is very useful when choosing some variables or functions with identical name).

2. Code navigation

Great thing is that you can follow your variables, functions and everything else in Outline window. I don't use it very often, but it is handy when I need to find something fast. You can click on element and program brings you to it's declaration.

You can bookmark line in your code, and then you can view all bookmarks in Bookmarks window.

Files window is sort of files explorer, and I don't use it, but it can be useful.

On the other hand, Project window is always when I'm working on my projects. Project window contains all files in your project structure. In fact it is folder of your project. From here you can inspect all files in your project, open them, rename, delete, etc.

3. Documentation generation

Lots of people aren't fans of documenting your code. I find it as general mistake since I know how hard is to get back on the project that you haven't work on for a long time.

For those smart enough to comment code, FD supports one neat feature. It is not default integrated but it is pretty simple to install. You can comment your code in Javadoc comments and click GENERATE ASDOC button in FlashDevelop. You have your ASDoc documentation for your classes. Really good way to make the best documentation for your code.

Final thought

These are just 3 general features that I use the most.

One thing I miss is debugger. I still use Flash debugger since it is really good. But even without debugger, this piece of work is best developing environment I've worked on. And it is free!

For more information on FlashDevelop visit FlashDevelop wiki pages or FlashDevelop forum.

23May/090

Send custom class through LocalConnection

http://www.flickr.com/photos/29487767@N02/2855271953/sizes/s/

Recently, I got my head around a problem of LocalConnection not working with sending data that is not simple data. I couldn't send my own classes through it.
I found a solution with registerClassAlias. You can read more about it:
registerClassAlias()

LocalConnection example

The example above is a demonstration of using registerClassAlias with LocalConnection, and sending custom class named TextData from Main.swf to LoadingSWF.swf.

Source files

15May/090

Dynamic MovieClip as button with clicked state

I created a simple class which allows you to convert MovieClip to button which has ability to be in clicked state, and also follows which button is active. Detailed description will be coming in later.

Source files

17Apr/090

Project life cycle

Project life cycle steps

1839810842_3ffe0144a8_m

1.Define requirements

Talk to your client, and get to know what is your project about. You'll get most of requirements, but I suppose not all. Don't worry, you'll be filled in when project kicks in.

2. Define project cost

First of all, break all requirements in small tasks.  Then, estimate how long do you need on getting that task done. Sum all hours and add some more time (which I call "safety time"), which will secure you in case your tasks get longer than you anticipated. After you did thatmultiply it with your hourly rate. You should get your project cost.

3. Write specification

If you are developer, and are working with other developers it's crucial to have some sort of standard between you. Specification gives you project goals and requirements. You can also include some programming language standards which your team will follow. Big projects have special person which takes care of this and it is absolutely must have, but if you are working alone, it could use you to have written standards. If project needs maintenance, you can return and read specification and know exactly what you need to do.

4. Plan your project

When you were estimating your project cost, you have broken requirements in smaller pieces. Now you can use that smaller pieces and put it in calender. Estimate how much a day will you work, and put tasks according to they priority. Include holidays and weekends in planning. You are done with project preparations.

5. Start working

Take that tasks and start working. If you are developer don't forget about importance of planning out your classes. :-)

6. Test it yourself

Write number of test and functionality your project needs to have, and do the testing. If you want, write down some bug list for future references. Maybe someday you'll be in the same position, having the same bug.

7. Have your client test it

It is important to have your client take a look of your project before it is finalized. That way you can get feedback from client and a new bug list. :-)

8. Document your project

When you have finalized your project take some time to document about it. Update your specification and write help on how to use your project.

Final thought

I hope I summarized basic steps of having a project on your hands from beginning to the end. If you have any comments, or you do it some other way I would appreciate your thoughts and opinions.

Regards,
Vjeko

16Apr/090

Twitter

twitter

Recently I went to Twitter. I was really skeptical, and still am. But one thing that is cool, you can found out news really quickly. Since Twitter allows only 140 characters, message is short and educative. On the other hand, users post a lot of messages. So you need time to read it all if you follow a lot of other users.

I just began with it didn't use much effort to add contacts, but surely will over time. If you want to add me, search me: Vjekoslav Ratkajec, or vratkajec.

Cheers,
Vjeko

Tagged as: No Comments
16Apr/090

Blog started…

As you see, there are few categories and I'll be filling them in soon enough. :-)

Cheers,
Vjeko

Filed under: News No Comments