AS3: How to Control Sound Channel of Another Scene from Inside a MovieClip? - actionscript-3

can you help me? Im a beginer im programming and I'm just barely know as3. I have a problem controlling my bg sound using as3 script from inside a movieclip.
I have an as3 flash project with multiple scene (let's say it sceneA and sceneB), and i placed my sound channel script at SceneA frame 1. I've been able to stop and play my music from sceneA without any trouble. Now at sceneB i have a movieclip and inside it, there's button stop and play. The problem is, I can't use the same method from sceneA to control my music from inside the movieclip of sceneB. How can i do it? Please i need your help.
Here's my sound channel script from sceneA frame 1:
var bgm:bgSound = new bgSound();
var sChnl:SoundChannel = new SoundChannel();
var myVolume:SoundTransform = newSoundTransform();
sChnl = bgm.play(0,999,myVolume);
Here's my sceneA button stop script, this button is called btnStop:
function musicStop(event:MouseEvent):void
{
SoundMixer.stopAll();
bntStop.visible=false;
btnPlay.visible=true;
}
Here's the play button called btnPlay:
function musicPlay(event:MouseEvent):void
{
sChnl = bgm.Play(0,999,myVolume);
bntStop.visible=true;
btnPlay.visible=false;
}
I tried the button play script from sceneA in my SceneB button play and it give me an error:
Symbol 'Symbol 1', Layer 'btn control', frame 1, Line 22 1120: Access of undefined property bgm.
That's one of the error massage, the other two is the same just that the bgm is myVolume and sChnl.
I have tried this function before
MovieClip(root).sChnl = bgm.Play(0,999,myMusic);
But it's not working.

Related

Flash AS3 movieclip doesn't stop motiontween and no errors are given

I have the following piece of code:
var Note1:MovieClip = mcNote1;
//Init
Note1.stop();
The instance name and everything is correct but yet it doesn't stop the movieclip??
Here a short overview of my flash file
You could try a couple things. You could edit your movie clip and insert a Keyframe and add "stop();" to frame 1 of your movieclip. Or you could try "Note1.gotoAndStop(1);" in your main function.

Play sound only on the first pass in Flash

I have an As3 simple game with navigation buttons. It starts off with short intro with sound. When the game loads and the player dies it goes to retry screen with button which when is pressed goes back to the game. The problem is that when that happens flash plays the music from the short intro when returning to the game. How Do I stop this from happening. Currently I have no code for the sound. I just added the music directly to the frame with the intro and that's it. So what code do I write for the sound to execute only once?
I googled 'as3 load sound' and this popped up
http://www.republicofcode.com/tutorials/flash/as3sound/
This will show you how to do it if the sound is in your library or if it's external.
With your audio file in the library right click on it and in properties>actionscript check export for actionscript and give it a class name yourAudioFileName
...then the code to start and stop will be
var mySound:Sound = new yourAudioFileName();
var myChannel:SoundChannel = new SoundChannel();
// start it with
myChannel = mySound.play();
// stop it with
myChannel.stop();

Flash CS 5.5 Actionscript 3 - Buttons appearing on all frames

I have a program that lets the user go to various functions, that all work. However when I use the music player function that i made the play and stop buttons remain on screen when i click back to return to the menu of options. Here is my code:
play_button.addEventListener(MouseEvent.CLICK,clickhandler);
stop_button.addEventListener(MouseEvent.CLICK,clickhandler);
function clickhandler(event:MouseEvent): void{
swapChildren(play_button, stop_button)
}
The music file is embedded in the buttons.
The following error appears every time:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at SmartHouse_Scene1_fla::MainTimeline/frame10()
at flash.display::MovieClip/gotoAndStop()
at SmartHouse_Scene1_fla::MainTimeline/fl_ClickToGoToAndStopAtFrame_27()
It should be noted that the error only occurs when the music has been played. I can go to the page and leave without the problem if i dont touch the play or stop button. If anyone could help i would really appreciate it.
if reading this correct the sounds are inside the button on the timeline, are you using buttons or movieclips, make sure that frame 27 exist on the movieClip timline.
//you can use// myMovieClip.visble = false;
example:
play_button.addEventListener(MouseEvent.CLICK,clickhandler);
function clickhandler(event:MouseEvent): void{
stage.myMovieClip.visible = false; // the name of your button clip
}

Flash CS6 AS3, Resetting Sound Channel

I've had a problem for a while trying to reset an audio loop to the beginning when loaded into Actionscript with this code i got from the official help forum
var alreadyExecuted:Boolean;
if(!alreadyExecuted){
alreadyExecuted=true;
var s:Sound=new SkaianSpirit();
var sc:SoundChannel=s.play(0,1);
}
What i want it to do, is loop indefinitely while the animation is playing regardless of positioning and whether or not frames have been skipped with buttons etc, but when the end of the animation comes, the track needs to end. At which point, if a button is clicked to send it back to the beginning of the animation, i want it to start the same loop as before.
Currently, it will do the first part, but will not replay.
A couple caveats:
I am not loading it through a url.
I am not using buttons to control audio volume etc. It is to play automatically when the animation starts.
I am a complete and utter novice with Actionscript. I will not know what you're talking about if you lambast me with jargon i won't understand.
I'd highly appreciate the help!
I'm always use addFrameScript function for synchronizing external sounds with animations:
UPD: mc is the name of your animation. Place this code in the place (the first frame of the parent Sprite that holds the animation for instance) where your animation is created.
var s:Sound=new SkaianSpirit();
var sc:SoundChannel;
mc.addFrameScript(1, startSound);
mc.addFrameScript(mc.totalFrames - 1, stopSound);
function startSound():void
{
sc = s.play();
}
function stopSound():void
{
sc.stop();
}

flash as3 fullscreen browser jams up playback

I have an AS3 project which when the user clicks a button the browser is set to fullscreen. This works great, however the playback sticks after the navigation is sent to the next frame. The MC on frame two plays, but then the playback head doesn't move forward to frame 3. Once escape is pressed, the fullscreen is broken and then the movie skips to where it would have been normally if it hadn't have gotten stuck on frame two (as if the project was running in the background). This problem also occurs without the fullscreen AS3, just using the controls for a projector to go to fullscreen, and it also occurs if the .swf file plays back directly in a flashplayer without the browser. I don't understand, without fullscreen, everything plays back perfectly....
Here's the code on frame 1:
fullscreenMe.addEventListener(MouseEvent.CLICK, fullScreenIt);
function fullScreenIt(event:MouseEvent):void {
MovieClip(root).gotoAndPlay('two');
stage.displayState=StageDisplayState.FULL_SCREEN;}
And here's the code on frame 2:
var titlesTimer = new Timer(11000,1);
titlesTimer.addEventListener(TimerEvent.TIMER_COMPLETE, titlesTimerFinished);
titlesTimer.start();
function titlesTimerFinished(e:TimerEvent):void {
//trace("timer is finished");
MovieClip(root).nextFrame();
}
var creditsSound:credits = new credits();
var creditsChannel:SoundChannel = new SoundChannel();
creditsChannel = creditsSound.play();
And here's the code on frame 3:
import fl.transitions.Tween;
import fl.transitions.easing.*;
function alphaTween(mc,b,f,d) {
var Alpha:Tween = new Tween(mc, "alpha", Regular.easeIn, b, f, d, true);
}
alphaTween(moon1,0,1,7);
var moonTimer = new Timer(1000,7);
moonTimer.addEventListener(TimerEvent.TIMER_COMPLETE, moonTimerFinished);
moonTimer.start();
function moonTimerFinished(e:TimerEvent):void {
//trace("timer is finished");
MovieClip(root).nextFrame();
}
Hmm from the information given I am not sure if the Playhead is in play mode or stop mode in a frame.
Before we can solve it
Is there a this.stop(); command added before any code is written in the frame. This ensures the Playhead is not in playing mode and stops in the present frame. If you want it playing, then no issues. But looking at the timers, I assume you must have added the stop() command.
Documentation for MovieClip for nextFrame says it sends the playhead to the next frame and stops it. This happens after all remaining actions in the frame have finished executing. So is this intended?