Posts Tagged ActionScript projects

Compile time variables in Flash Develop

That is something that I have been wanting for a long time but I just found out how to do it.

So what is a compile time variable?

It is a variable that you can do conditions on at compile time (if) and the compiler will only include a set of lines in the resulting swf. This can be usefull for debugging purpose or when you have multiple languages or versions in a site. Let’s look at an example:

if (CONFIG::LANG == "en"){
  _pageHolder = new PageHolderEn();
} else {
  _pageHolder = new PageHolderFr();
}

In the previous code, if the compile time variable CONFIG::LANG is equal to “en”, than the line “_pageHolder = new PageHolderEn();” will be included in the final swf, otherwise it will be the other line. You can give a Boolean, int and String value (and probably other types too) to the variable.

So how do you set the value of that compile time variable?

Well there are a couple of examples out there about how to do so in Flash CS4 IDE or in Flash(Flex) Builder, but none in Flash Develop so that is what I am going to explain here. First if you do this in Flash Develop, it means you are either doing a Flex project or an ActionScript project (meanin you are compiling with the Flex compiler (is it still named like this?)). So once you have created your project, go in the Project Properties and in the Compiler Options tab, look for the Additional Compiler Options. Here is a screenshot of what it looks like:

compile-time

What you need to add in there is this:

-define+=CONFIG::LANG,"en"

Where CONFIG::LANG is your variable name and “en” is the value as a String.  For the variable name it seems to always be starting with CONFIG::, I don’t know if that is a convention or if that is needed so that the compiler knows its a compile time variable. I will need to do more reasearch on this. If you wanted to set the variable to a boolean you’d do this:

-define+=CONFIG::LANG,true

And same principle for a int, you’d put just the number without the quotes.

Now in Flash Develop, the project properties are stored in a file with the .as3proj extention so if you don’t want to have to change the Additional Conpiler Option you can just copy the project file and rename it. In the new file change the compile time value and depending how you want to compile, you open the right project file.

Well, it’s as simple as this.

, , , ,

No Comments


PureMVC Skeleton for ActionScript projects

I had previously done a PureMVC skeleton for Flash websites and applications, meaning that you would use the Flash IDE compiler to compile your project. Lately I have been doing more and more ActionScript projects (compiled using the Flex compiler but not using the Flex framework) because it permits the separation of big FLAs into smaller ones thus facilitating working in team. But I had no template/skeleton to start with until now.

So here it is:

PureMVC ActionScript Project Skeleton

It still uses an external preloader and I added a local Boolean so that the application knows your are testing locally and not on the sever (useful when making server call). One of the major change is the inclusion of the SharedAssetLibrary. Basically this emulate having one FLA with all graphics and MovieClip, but you actually can have multiple FLAs. When you want to add something to the SharedAssetLibrary you first add it to a FLA, set it to Export for ActionScript and then compile it to the swf folder. Then you can add it in the SharedAssetLibrary using the embed statment:

//BackgroundAsset being the name you gave it in the library
 
[Embed(source="../../../swf/Background.swf", symbol="BackgroundAssets")]
public var BackgroundAssets:Class;

Now if you want to use this in any of your views, first import SharedAssetLibrary and than you can use it like this:

var BackgroundAssets:Class = SharedAssetsLibrary.getInstance().getAsset("BackgroundAssets");
var assets:* = new BackgroundAssets();
addChild(Sprite(assets));

I included a FlashDevelop project file in there, but you can just delete it if you use Flash Builder.

Using a skeleton greatly reduce the setup time of a project, so I hope this will help you. I want to look into doing a skeleton for Flex Application, because I don’t like the skeleton that is available on the PureMVC website.

, , , ,

6 Comments