I'm ready to give up as I've already started losing my hair. I'm trying to create two simple sound control buttons. I've created the buttons, imported the mp3 file, converted the buttons to button symbols, and have exported them to actionscript3. Here is the code that I have writted in the first frame:
var soundReq: URLRequest = new URLRequest ("bgmusic.mp3");
var sound: Sound = new Sound();
var SoundControl: SoundChannel = new SoundChannel();
sound.load(soundReq);
sound.addEventListener(Event.COMPLETE, onComplete);
PlayButton.addEventListener(MouseEvent.CLICK, playSound);
StopButton.addEventListener(MouseEvent.CLICK, stopSound);
function playSound(event:MouseEvent):void
{
soundControl = sound.play();
}
function stopSound(event:MouseEvent):void
{
soundControl = sound.stop();
}
I'm getting this:
multi scroller, Layer 'actions', Frame 2, Line 116 1120: Access of undefined property soundControl.
multi scroller, Layer 'actions', Frame 2, Line 121 1120: Access of undefined property soundControl.
multi scroller, Layer 'actions', Frame 2, Line 121 1061: Call to a possibly undefined method stop through a reference with static type flash.media:Sound.
multi scroller, Layer 'actions', Frame 2, Line 110 1120: Access of undefined property onComplete.
multi scroller, Layer 'actions', Frame 2, Line 111 1061: Call to a possibly undefined method addEventListener through a reference with static type Class.
multi scroller, Layer 'actions', Frame 2, Line 112 1061: Call to a possibly undefined method addEventListener through a reference with static type Class.
Do you have any advices for me? Thanks in advance.
1. var SoundControl: SoundChannel = new SoundChannel();
and you omited the caps (S) everywhere soundControl, change the variable declaration to soundControl
This is the final code:
var soundReq:URLRequest = new URLRequest("snd1.mp3");
var sound: Sound = new Sound();
var soundControl: SoundChannel = new SoundChannel();
sound.load(soundReq);
PlayButton.addEventListener(MouseEvent.CLICK, playSound);
StopButton.addEventListener(MouseEvent.CLICK, stopSound);
function playSound(e:MouseEvent):void
{
soundControl = sound.play();
}
function stopSound(event:MouseEvent):void
{
soundControl.stop();
}
1) multi scroller, Layer 'actions', Frame 2, Line 116 1120: Access of undefined property soundControl.
multi scroller, Layer 'actions', Frame 2, Line 121 1120: Access of undefined property soundControl.
The first errors involves a misspelling... SoundControl != soundControl
2) multi scroller, Layer 'actions', Frame 2, Line 121 1061: Call to a possibly undefined method stop through a reference with static type flash.media:Sound.
soundControl = sound.play(); // is okay, but to stop it...
soundControl.stop();
3) multi scroller, Layer 'actions', Frame 2, Line 110 1120: Access of undefined property onComplete.
I don't see any onComplete function defined anywhere
4) multi scroller, Layer 'actions', Frame 2, Line 111 1061: Call to a possibly undefined method addEventListener through a reference with static type Class.
multi scroller, Layer 'actions', Frame 2, Line 112 1061: Call to a possibly undefined method addEventListener through a reference with static type Class.
PlayButton.addEventListener(MouseEvent.CLICK, playSound);
StopButton.addEventListener(MouseEvent.CLICK, stopSound);
My guess is you are using the class names of the buttons (bolded text), not the instance names.
hi. i am having a similar issue. I dont want to impose, so if you all think my issue should be posted it in a new thread, let me know.
In any case, noting this thread has not been answered, i have an idea for Krizeto
use a btn component - one on top of the other in one frame,
and the code below:
start_btn.visible = false
stop_btn.addEventListener(MouseEvent.CLICK, stopMusic);
function stopMusic(e:Event){
SoundMixer.stopAll();
start_btn.visible = true;
stop_btn.visible = false;
}
start_btn.addEventListener(MouseEvent.CLICK, startMusic);
function startMusic(e:Event){
music_mc.gotoAndPlay(1);
stop_btn.visible = true;
start_btn.visible = false;
}
As for my own issue - what i have is an fla w/ some frames and btns that navigate the frames, and i want differnt music on each differnt frame, but i cant get the music from the first frame to stop when i go to the next.
here is my code:
import flash.events.MouseEvent;
import flash.media.Sound;
stop();
var bgmusic:Sound = new tzipi;
bgmusic.play();
if(currentFrame == 10)
{
bgmusic.stop();
}
Without the "if" statement the music plays fine, but as said, it wont stop on the next frame and using bgmusic.stop() outputs an error -
| 1061: Call to a possibly undefined method stop through a reference with static type flash.media:Sound. |
thanks.
North America
Europe, Middle East and Africa
Asia Pacific