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

Help with sound on Animate (Loop and Scene Switching) AS3

New Here ,
Jul 16, 2024 Jul 16, 2024

Copy link to clipboard

Copied

Hello how's everyone doing? I'm trying to achieve adding background music to a project. The timeline is pretty empty, it has 1 keyframe for each layer. I need to import this song and to make it repeat on loop infinitely until it loads another scene on the main game that I think is coded on "Visual Studio". All the scenes are individual .fla I don't have access.

 

I imported the sound and linked as "BackgroundMusic". As I didn't find any tutorials, I prompted ChatGpt and gave me this code:

 

import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.Event;

// Create a Sound object and a SoundChannel object
var bgMusic:BackgroundMusic = new BackgroundMusic();
var bgMusicChannel:SoundChannel;

// Function to start playing the music
function playMusic():void {
// Stop any previously playing sound
if(bgMusicChannel) {
bgMusicChannel.stop();
}
// Play the new sound in a loop
bgMusicChannel = bgMusic.play(0, int.MAX_VALUE);
}

// Function to stop playing the music
function stopMusic(event:Event):void {
if(bgMusicChannel) {
bgMusicChannel.stop();
}
}

// Start playing the music when the scene is loaded
playMusic();

// Stop the music when the scene is removed from the stage
this.addEventListener(Event.REMOVED_FROM_STAGE, stopMusic);

Thanks to everyone taking the time to read and help ♥

TOPICS
ActionScript

Views

48

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 ,
11 hours ago 11 hours ago

Copy link to clipboard

Copied

code looks ok for an as3 project.

 

is this an as3 project, or canvas?

 

if as3, show your library to confirm BackgroundMusic is correctly assigned.

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
New Here ,
10 hours ago 10 hours ago

Copy link to clipboard

Copied

Thanks for repying! Here it's a screenshot of my library! Captura de pantalla 2024-07-17 020901.png

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
Community Expert ,
8 hours ago 8 hours ago

Copy link to clipboard

Copied

LATEST

that looks ok, too.

 

for testing, import a wav or mp3 file that's been opened in audition and resaved with 44.1 sample rate.

change BackgroundMusic linkage to bgm_bu

and assign linkage BackgroundMusic to the newly imported sound file

test

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