Subcribe via RSS

Localizing Flash content with Strings panel

May 26th, 2011 | No Comments | Posted in Flash

In the tricky job of creating multilanguage content, Flash provides us with the Strings panel that makes our lifes easier.

This panel is accessed from Windows > Other Panels > Strings and in order to add languages to our movie we need to click the Settings button.

Once we have added the languages, we need to specify which language we want as a default and the method that is going to be used to replace the strings.

We can choose between three different methods:

  • Automatically at runtime: Flash will detect the language used in the computer and it will be applied as the language of the movie.
  • Manually using stage language: We have an option in the same Strings panel where we can select the language. The movie will use that language in the output file.
  • Via ActionScript at runtime: With ActionScript we can pick the language at runtime and change it when needed. This option is very handly if we need to allow the user to change the language of the movie.



Now we are ready to start feeding the Strings panel with text entries!

First we have to fill the identifier and the string and press the button Apply. Take special attention at the stage language selected as the string will be added to that language. You can add or modify all the strings easily later in the grid below.

In order to attach a string to a textfield in our movie we need to select the textfield on the stage and select the string in the Strings panel. Pressing the button Apply will do the job.

Now we can do a quick test selecting in the Settings Manually using stage language and if we go ahead and change the stage language we will see that the textfields are updated!

When we save the movie, Flash will save XML files for the different languages. Every language will be stored inside a different folder with the identifier of the language as the name. These XML files can be imported to the Strings panel pressing the button Import XML.

For more information you can have a look here at the Adobe official documentation.


Enjoy localizations!

Singleton Pattern in ActionScript 3

May 15th, 2011 | No Comments | Posted in ActionScript3

As AS3 does not support the use of private constructors, we have to use a workaround in order to implement the Singleton pattern.

We can find lots of different approaches on the Internet as for example the following:

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
  package  {
 
  public class SingletonClass {

    private static var _instance:SingletonClass;

    public function SingletonClass(enforcer:SingletonEnforcer) {
      if (enforcer == null) {
        throw new Error("SingletonClass is a Singleton class and must be accessed using getInstance()");
      }
    }
   
    public static function getInstance():SingletonClass {
      if (_instance == null) {
        _instance = new SingletonClass(new SingletonEnforcer());
      }
      return _instance;
    }
   
    public function testFunction():void {
      trace("test function");
    }
  }
}

class SingletonEnforcer {}

We use an intenal class called SingletonEnforcer in the constructor. The class is defined outside the package and it will be accessible only from the classes inside the .as file. This way we prevent the instantiation of our Singleton class without the use of the method getInstance().

The next approach is much more neat and looks like the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package  {
 
  public class SingletonClass {
   
    private static var _instance:SingletonClass = new SingletonClass();

    public function SingletonClass() {
      if (_instance) throw new Error("SingletonClass is a Singleton class and must be accessed using getInstance()");
    }
   
    public static function getInstance():SingletonClass {
      return _instance;
    }
   
    public function testFunction():void {
      trace("test function");
    }
  }
}

This implementation looks much better but creates an instance automatically, and sometimes we would prefer to have the class in memory only when we need it.

The last approach I think it’s the best from my point of view:

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
package  {
 
  public class SingletonClass {

    private static var _instance:SingletonClass;
    private static var _allowInstance:Boolean;

    public function SingletonClass() {
      if (!_allowInstance) throw new Error("SingletonClass is a Singleton class and must be accessed using getInstance()");
    }
   
    public static function getInstance():SingletonClass {
      if (_instance == null) {
        _allowInstance = true;
        _instance = new SingletonClass();
        _allowInstance = false;
      }
      return _instance;
    }
   
    public function testFunction():void {
      trace("test function");
    }
  }
}

As I said before, there are multiple ways of implementing this design pattern. In an ideal world we will be able to use private constructors in ActionScript, but meanwhile this happens we can use our customized Singleton classes in AS3!


Cheers.

BlendMode.LAYER, alpha and overlapping child DisplayObjects

May 10th, 2011 | No Comments | Posted in ActionScript3

We need lots of times to change the alpha property of a DisplayObject in our projects. Almost all the times we will be happy with the effect, but we can come across with an unexpected result.

If we apply for instance alpha to a MovieClip that contains overlapping MovieClips, we will see that the container MovieClip will be displayed with an unpleasant effect.

What happens is that Flash Player applies alpha to every child MovieClip inside it’s parent independently.

In order to solve this problem, we can use BlendMode.LAYER that tells Flash Player to apply alpha to a DisplayObject as only one layer getting the result we may need.

You can give it a try and notice the differences with the following example:

This movie requires Flash Player 9
.
Considering our container MovieClip is called myMc, we need the following ActionScript in order to enable this mode:

1
  myMc.blendMode = BlendMode.LAYER;

There are more interesting values in the BlendMode class. You can check them out in the Adobe Flash online documentation clicking here.


Happy coding!

Monster Debugger 3 has been released

May 1st, 2011 | No Comments | Posted in General

Monster Debugger is a great application created by De Monsters that let us debug our Flash, Flex and AIR applications.

I was amazed when I started using it in previous versions because it’s so easy to use and so powerful. Now, Monster Debugger 3 is here and it comes with lots of new cool stuff.

In order to learn the features of this debugger, the developers have created a game that needs the use of the debugger itself to hack the game to finish it.

I encourage you to visit http://demonsterdebugger.com and give it a try. It’s worth it!

 

Hello world!

May 1st, 2011 | No Comments | Posted in General

I think it’s important to share our experiences as developers with the others. I could count thousands of times when I found a solution or I was able to understand better something I was working on and, almost all of the times, thanks to a blog.

Today, I am pleased to start this blog that will talk mainly about Flash technology. I would like to contribute this way to the Adobe Flash Community with my daily experience and I hope someone may find it helpful.

Of course, all the comments and suggestions are really appreciated.

Welcome to Flash Inside!

 

Alejandro Mendez