Subcribe via RSS

Brand new property MovieClip.isPlaying

January 18th, 2012 | 2 Comments | Posted in ActionScript3

I have discovered recently the new isPlaying property for the MovieClip class that Adobe introduced in Flash Player 11.

I do recommend you read What’s New in Flash Player 11 where you will find interesting new features like this one.

It’s great we finally have an easy way to know if our animations are running or simply stopped.

Take a look at the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import flash.events.Event;
import flash.events.MouseEvent;

this.addEventListener(Event.ENTER_FRAME, onLoop);
stage.addEventListener(MouseEvent.CLICK, onClick);

mc.play();

function onLoop(e:Event):void
{
txtInfo.text = mc.isPlaying ? "MovieClip playing!" : "MovieClip stopped";
}

function onClick(e:MouseEvent):void
{
if (mc.isPlaying) {
mc.stop();
} else {
mc.play();
}
}

As we see the use of this property keep things very simple and this is really welcome! Quite surprising this has not been available before.

Note the mc.play() in line 7. It seems this property does not know the MovieClip is playing by default, and the value gets updated when we use the MovieClip playback functions such as play(), stop() and so on…

If you are going to use the isPlaying property ensure to use those functions to have the correct value.

This is the result of the above code (Flash Player 11 required):

This movie requires Flash Player 9

You can download this example in Flash CS5 here.

UPDATE: I forgot to mention you need to target Flash Player 11 in your Flash IDE. This is not available by default in Flash CS5 or CS5.5 as you can only select up to Flash Player 10.2. In order to add Flash Player 11 follow the instructions explained here.

Important: If you run the movie within the Flash IDE it won’t work. The movie will be played by Flash Player 10.2. Test your published SWF file in your browser. You can now download the Release/Debug Flash Player 11.1 from the Adobe website here.

Resizing your content with 9-slice scaling

January 11th, 2012 | 2 Comments | Posted in Flash

I’ve found these days some designers and even programmers not aware of the 9-slice scaling that Flash provides, and that’s why I’d like to introduce it here for those who does not know it either.

This feature allows you to determine the way a MovieClip is scaled. Doing that you will be able to resize without unwanted results like your MovieClip is distorted.

With tablets and smart phones on the market, it’s a good idea to resize our content accordingly to the area we have available, and here is where 9-slice scaling will help you out.

Look at the picture below and notice the rounded corners it has:

Now look at the difference we get after applying an horizontal resize of the MovieClip:

As you can see with 9-slice scaling we can achieve the result we really expect.

In order to enable this feature, you just need to open the Properties panel of the MovieClip and select Enable guides for 9-slice scaling as shown in the picture below:

Then when you edit the MovieClip it will show you the guides that you can easily adjust to your needs as seen in the following picture:

This scaling mode cannot be applied to Buttons or Graphics Symbols. The same applies when we nest them inside a MovieClip. The 9-scale scaling will only be applied to the compatible content.

It would be perfect to have 9-slice scaling for Bitmaps as a built-in capability in Flash, but meanwhile Grant Skinner created a nice solution called BitmapSlice9. It allows you to break your Bitmaps in pieces and use the 9-slice scaling with a great results!

UPDATE: You can download this example in Flash CS5 here.