Archive for category ActionScript

Flash Preload Refresh Freeze

If you have an ActionScript preloader for your flash movie, it might work when you first load, once you refresh, the preloader might hang there and freezes.

This could be caused by a few problems in your preloader.

1. Check if you have a Event.COMPLETE listener for your loaderInfo, you should have a function and event listener like the one below in your loader script:

this.loaderInfo.addEventListener(Event.COMPLETE, goToNext);
function goToNext(e:Event):void {
	this.loaderInfo.removeEventListener (Event.COMPLETE, playtwo);
	this.gotoAndStop(2);
}

2. Put a random function to your HTML page that loads the Flash Movie swf.

For instance, if you use SWFObject to load the swf, by default, it looks like:
swfobject.embedSWF("main.swf, "my_flash", "100%", "100%", "9.0.0","expressInstall.swf", flashvars, params, attributes);

change it to:
swfobject.embedSWF("main.swf?t="+new Date().getTime(), "my_flash", "100%", "100%", "9.0.0","expressInstall.swf", flashvars, params, attributes);

3. Put it on a server. Sometimes if you run the HTML locally, it might have problem. Upload it to a server or your localhost, run it from http://www.abc.com/ will solve the problem.

Hope these tips work for you. :)

1 Comment

ActionScript Fading Sound Music

In Flash, if you use ActionScript to load music dynamically and want to fade the sound, you can use the famous Tweener library to do so. Below is an ActionScript 3 example of how to load and fade in the sound:

First, you have to load in the Tweener Class, Tweener SoundShortcuts and initialize the SoundShortcuts:

import caurina.transitions.Tweener;
import caurina.transitions.properties.SoundShortcuts;
SoundShortcuts.init();

Now we can load the sound and add the tween to fade the sound

var music:Sound = new Sound(new URLRequest("intro.mp3"));
var sc:SoundChannel;
sc = music.play();
Tweener.addTween(sc, {_sound_volume:1, time:5, transition: "easeInOutQuad"});

1 Comment

as3 getURL

In this article, we will see ActionScript 3′s equivalence of getURL. For instance, if you have a button instance named myButton, and you want to go to google.com

In AS2, you would do something like:

myButton.onRelease = function() {
getURL("http://www.google.com");
}

In AS3, you must use the function like the one below:

myButton.addEventListener(MouseEvent.CLICK, onMouseClick);

function onMouseClick(e:MouseEvent):void {
var request:URLRequest = new URLRequest("http://www.google.com");
navigateToURL(request, "_blank");
}

Hope this helps!

1 Comment

as3 useHandCursor

In as3, to use useHandCursor is easy, to use a hand cursor on a MovieClip that has event listeners (for example, a CLICK event) – you simply need two lines of code to use a hand cursor, if you have a MovieClip named myMC, type the following code:

myMC.buttonMode = true;
myMC.useHandCursor = true;

Hope this helps. :)

No Comments

Add swc to an existing Flex Project

There are many swc Class Library Distribution for Flex ActionScript. To import a .swc to your existing Flex ActionScript project is easy. Let’s use the tweener library as an example.

1. In your Flex builder, from the Flex Navigator, right click on the project, at the end of the menu, there is a Properties option, click on it.

2. A pop up window will be opened, click on the ‘Library Path’ tab in the window.

3. On the Library path tab, click Add SWC.

4. Browse to and select the file tweener.swc from the preceding section, then click Finish.

5. To use the library, just add the following line to your package:

import caurina.transitions.Tweener;

No Comments

AS3 Tweening

To do Flash tweening in ActionScript 3 is different from doing it in Actionscript. The change is not so fundamental, more on the appearance.

To use the Flash tweening class in ActionScript 2, what you do is:

import mx.transitions.Tween;
import mx.transitions.easing.*;
var myTweenAlpha:Tween = new Tween(rectangle, "_x", Bounce.easeOut, 0, 1, 3, true);

In ActionScript 3, the same action can be done in the following way:
import fl.transitions.Tween;
import fl.transitions.easing.*;
var myTweenAlpha:Tween = new Tween(rectangle, "x", Bounce.easeOut, 0, 1, 3, true);

No Comments

AS3 _alpha

In ActionScript 2, you use _alpha to set the transparency of movieclips, in ActionScript 3, this no longer works. But instead, there is a new method provided.

In ActionScript 2, to set alpha value, you may do something like this:

a_mc._alpha = 40;

In ActionScript 3, you need to do something like this to achieve the same result:

a_mc.alpha = .4;

From the above example, we can see that two things are changed in ActionSctipt 3:

1. the first thing is that in ActionScript 3, instead of using ‘_alpha’, now we use ‘alpha’ as the property name.
2. the second thing is that instead of defining the value of color in a scale of 0-100, now we define alpha in 0.00-1.

Hope this help those migrate from AS2 to AS3.

No Comments

AS3 setMask

In Flash, to set dynamic mask in ActionScript 3 is a bit different from setting it in ActionScript 2.

To set mask in ActionScript 2, you use the method below:

a_mc.setMask(b_mc);

To transform the above ActionScript 2 script to ActionScript 3:

a_mc.mask = b_mc;

As you can see, by comparing the two versions of ActionScript, obviously, the later one is much cleaner and makes more sense from programming perspective.

1 Comment

AS3 onMotionStopped

Today, I have learned many things about ActionSctipt 3. I used a lot ActionScript 2 in the past, now at new work, I am trying my very best to pick up on ActionScript 3. Compare to ActionScript 2, ActionScript 3 is a much more powerful language.

One problem I had while experimenting with AS3 is that when I try to use the onMotionStopped, it’s not supported anymore. It took me a while googling to find out the new way of doing it.

In ActionScript 2, you may use this:


import mx.transitions.Tween;
import mx.transitions.easing.*;
var tw:Tween = new Tween(myObject,"x",Strong.easeIn,20,100,1,true);
tw.onMotionStopped = function() {
trace("Tween stopped");
}

The new class that has been introduced in AS3 is fl.transitions.TweenEvent;

So in ActionScript 3, you have to do this:

import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
var myTween:Tween = new Tween(circle, "x", Elastic.easeOut, 0, 300, 3, true);
myTween.addEventListener (TweenEvent.MOTION_FINISH, motionEnd);
function motionEnd (e:Event)
{
trace ("finished");
}

No Comments

Flash text field alpha

Today, my colleague and I had a problem when setting alpha for a dynamic text field in Flash. After setting it to 50%, it still shows 100% when we publish the movie. Setting text field alpha in Flash may have no actual effect. If the TextField is a dynamic one, you need to either put the TextField in a MovieClip or Embed font for the TextField in order to make alpha work in Flash.

No Comments