Jump to content

Not stopping?


Twango

Recommended Posts

I'm new to flash, i use CS5, and i have a problem.... i simply want to click on somthing i drew to make it stop.... sounds simple? right?Nope.I cant get it to work! heres the code i have:Buttonit.addEventListener(MouseEvent.CLICK, fl_ClickToStop);function fl_ClickToStop(event:MouseEvent):void{ stop();}What am i doing wrong?!?!?!?? please help :)

Link to comment
Share on other sites

Hi!Try This Code:You could add a test inside the playChimes function to see whatstatus.text is.If the chimes are off, turn them on, and if they're on, turn them off.If we use status.text for our test, we don't need the chimesStatus Boolean(unless you're using that for something else as well).AS3.0 Example 1:

import flash.media.Sound;import flash.media.SoundChannel;status.text = "Chimes Off";playButton.addEventListener(MouseEvent.MOUSE_DOWN, playChimes);// declare chimesSound here, so it's within scope of the else part of our // conditional statementvar chimesSound:SoundChannel; function playChimes(e:MouseEvent):void{  if(status.text == "Chimes Off") // chimes are off, so turn them on  {	var chimes:Chimes = new Chimes();	chimesSound = chimes.play();	status.text = "Chimes On";	var chimesStatus:Boolean = true;  // ? maybe don't need this if we're using status.text in our test	trace ("Playing!");  }  else // chimes are on, so turn them off  {	chimesSound.stop();           status.text = "Chimes Off";  }}

Another Example:You will need to create two buttons one that will be your play/pause button and another that that will be your stop button. Also be sure to define the path of the sound file.AS3.0 Example 2:

//number that is redefined when the pause button is hitvar pausePoint:Number = 0.00;//a true or false value that is used to check whether the sound is currently playingvar isPlaying:Boolean;//think of the soundchannel as a speaker system and the sound as an mp3 playervar soundChannel:SoundChannel = new SoundChannel();var sound:Sound = new Sound(new URLRequest("SOUNDPATH/EVENDEEPER/SOUND.mp3"));//you should set the xstop and xplay values to match the instance names of your stop button and play/pause buttonsxstop.addEventListener(MouseEvent.CLICK, clickStop);xplay.addEventListener(MouseEvent.CLICK, clickPlayPause);soundChannel = sound.play();isPlaying = true;function clickPlayPause(evt:MouseEvent) {	if (isPlaying) {		pausePoint = soundChannel.position;		soundChannel.stop();		isPlaying = false;	} else if (!isPlaying) {		soundChannel = sound.play(pausePoint);		isPlaying = true;	}}function clickStop(evt:MouseEvent) {	if (isPlaying) {		soundChannel.stop();		isPlaying = false;	}	pausePoint = 0.00;}

If AS3.0 Is Tough For You, You Can Use AS2.0 Too... It's Easier Than AS3.0Download Sample AS2.0View Sample AS2.0

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...