Archive | Flash RSS for this section

Delay action in Action Script 3 (Flash)

To delay a flash action for some times, you can use this code:

var myDelay:Timer = new Timer(30000,1);
myDelay.addEventListener(TimerEvent.TIMER, showMessage);
myDelay.start();
function showMessage(event:TimerEvent):void{
gotoAndPlay("enterMain");
}
stop();

Advertisements

Playing with sound in Action Script 3 (Flash)

To play an external audio files:

var hisPromise:Sound = new Sound();
var hisPromiseChannel:SoundChannel = new SoundChannel();
hisPromise.load(new URLRequest("audio/01_His_Promise_is_Forever.mp3"));
hisPromiseChannel = hisPromise.play();

to stop:

hisPromiseChannel.stop();

to adjust volume (range 0 – 1):

hisPromiseChannel.soundTransform = new SoundTransform(0.2);

to Pause:

lastPosition = myChannel.position;
myChannel.stop();

to Play from last position:

myChannel = mySound.play(lastPosition);

to Loop sound:

var hisPromise:Sound = new Sound();
var hisPromiseChannel:SoundChannel = new SoundChannel();
hisPromise.load(new URLRequest("audio/01_His_Promise_is_Forever.mp3"));
playSound();
function playSound():void
{
hisPromiseChannel = hisPromise.play();
hisPromiseChannel.addEventListener(Event.SOUND_COMPLETE, onComplete);
}
function onComplete(event:Event):void {
SoundChannel(event.target).removeEventListener(event.type, onComplete);
playSound();
}