• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Set different background sound for labels

Explorer ,
Oct 08, 2017 Oct 08, 2017

Copy link to clipboard

Copied

Hi guys,

How to set different background sound if I have 3 labels.

For example, I have 3 settings like : Market, School, and Beach.

Everytime user change their option, we move to different label using gotoAndPlay("beach") for example.

Then, how to change the background music right after they choose another place?

2017-10-09.png

I've found some script like:

Script

var snd:Sound = new SoundPlay();
       var channel1:SoundChannel = new SoundChannel();

       channel1 = snd.play();

But I'm not sure how to use it in different labels.

Thank you.

TOPICS
ActionScript

Views

321

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 08, 2017 Oct 08, 2017

Copy link to clipboard

Copied

LATEST

I hope it helps!

FLA: https://goo.gl/3YgtvP

Code:

import flash.events.MouseEvent;

import flash.media.Sound;

import flash.media.SoundChannel;

import flash.media.SoundTransform;

import flash.net.URLRequest;

var sChannel:SoundChannel;

var bgmList:Vector.<String> = new <String>

[

     "bgm/369711__mrguff__hit-impact.mp3",

     "bgm/146718__fins__button.mp3",

     "bgm/264446__kickhat__open-button-1.mp3"

];

function playSound(path:String, volume:Number = 1, start:Number = 0, loops:int = 0):void

{

     var sound:Sound = new Sound();

     var sTransform:SoundTransform = new SoundTransform();

     if (sChannel) sChannel.stop();

     sound.load(new URLRequest(path));

     sChannel = sound.play(start, loops);

     sTransform.volume = volume;

     sChannel.soundTransform = sTransform;

}

function onMouse(e:MouseEvent):void

{

     if (e.type == MouseEvent.CLICK)

     {

          if (e.currentTarget == button1)

          {

               playSound(bgmList[0], 1, 0, 100);

               gotoAndPlay("bgm1");

          }

          else if (e.currentTarget == button2)

          {

               playSound(bgmList[1], 1, 0, 100);

               gotoAndPlay("bgm2");

          }

          else if (e.currentTarget == button3)

          {

               playSound(bgmList[2], 1, 0, 100);

               gotoAndPlay("bgm3");

          }

     }

}

button1.addEventListener(MouseEvent.CLICK, onMouse);

button2.addEventListener(MouseEvent.CLICK, onMouse);

button3.addEventListener(MouseEvent.CLICK, onMouse);

stop();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines