Controlling sound file with play, stop and mute button in AS3.0?

the method for stopping/playing sound in 2.0 don't work for 3.0.  i can stop the sound by going to a different page/frame on the site.  but i want the buttons. 
1. play button?
2.stop button?
3.mute button?
thanks in advance!

for pause (example 2) :
for volume -mute (example 1) :
package
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.*;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundTransform;
import flash.net.URLRequest;
import flash.utils.Timer;
public class SoundTransformExample extends Sprite
  private var url:String = "MySound.mp3";
  private var soundFactory:Sound;
  private var channel:SoundChannel;
  private var positionTimer:Timer;
  public function SoundTransformExample()
   stage.align = StageAlign.TOP_LEFT;
   stage.scaleMode = StageScaleMode.NO_SCALE;
   var request:URLRequest = new URLRequest(url);
   soundFactory = new Sound();
   soundFactory.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
   soundFactory.load(request);
   channel = soundFactory.play();
   stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
  private function ioErrorHandler(event:Event):void
   trace("ioErrorHandler: " + event);
  private function setPan(pan:Number):void
   trace("setPan: " + pan.toFixed(2));
   var transform:SoundTransform = channel.soundTransform;
   transform.pan = pan;
   channel.soundTransform = transform;
  private function setVolume(volume:Number):void
   trace("setVolume: " + volume.toFixed(2));
   var transform:SoundTransform = channel.soundTransform;
   transform.volume = volume;
   channel.soundTransform = transform;
  private function mouseMoveHandler(event:MouseEvent):void
   var halfStage:uint = Math.floor(stage.stageWidth / 2);
   var xPos:uint = event.stageX;
   var yPos:uint = event.stageY;
   var value:Number;
   var pan:Number;
   if (xPos > halfStage)
    value = xPos / halfStage;
    pan = value - 1;
   else if (xPos < halfStage)
    value = (xPos - halfStage) / halfStage;
    pan = value;
   else
    pan = 0;
   var volume:Number = 1 - (yPos / stage.stageHeight);
   setVolume(volume);
   setPan(pan);
 package
import flash.display.Sprite;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.events.MouseEvent;
import flash.text.TextFieldAutoSize;
public class SoundChannel_stopExample extends Sprite
  private var snd:Sound = new Sound();
  private var channel:SoundChannel = new SoundChannel();
  private var button:TextField = new TextField();
  public function SoundChannel_stopExample()
   var req:URLRequest = new URLRequest("MySound.mp3");
   snd.load(req);
   button.x = 10;
   button.y = 10;
   button.text = "PLAY";
   button.border = true;
   button.background = true;
   button.selectable = false;
   button.autoSize = TextFieldAutoSize.CENTER;
   button.addEventListener(MouseEvent.CLICK, clickHandler);
   this.addChild(button);
  private function clickHandler(e:MouseEvent):void
   var pausePosition:int = channel.position;
   if (button.text == "PLAY")
    channel = snd.play(pausePosition);
    button.text = "PAUSE";
   else
    channel.stop();
    button.text = "PLAY";

Similar Messages

  • No sound at all for incoming calls, txts, games i tried everything reset, restore , delete content and reset , reset network settings. Alarm sounds work but notification sounds don't work please and mute button is in ring mode

    No sound at all for incoming calls, txts, games. I have checked the side mute switch. Volume is all way up. All notifications are on.  I can hear tones when I go to change them. I can hear my music.  I can hear talking on videos I have taken.  I have tried everything I know to do(reset,restore,reset network settings,reset content and other settings and mute button is not ON)Please help!

    This is exactly the same problem I am having. I dropped the phone one time I think that was the reason. Now I cant seem to find any solution to fix it and it will cost me $149 to buy a new phone? There has to be a way to fix this problem.
    When I put it in speaker phone I can hear but not voices through the phone.

  • Missing buttons, i.e., the play, stop and FF buttons...along with loops

    Im not very GB savvy, but I know that I had been avoiding the update, and it worked fine before I left the house for my Kick 'n' Zumba class. My husband wanted to make some ringtones for our phones, and I got a text that said our GB was broken. So he says he didnt update it, but when I check for updates, there are none. GB is running on version 4.1.2. Any ideas? And when I open previously made ringtones, the added loop (is that what it is?, the song from iTunes) is missing also. What happened

    It's hard to say without knowing exactly what happened at your Kick 'n' Zumba class.
    Perhaps some basic troubleshooting might help: There are 2 preference files associated with Garageband. Try throwing both of them out, and then open Disk Utility and Click on Repair Disk Permissions.

  • My audio stops outputting after a few songs in a playlist - itunes says its still playing, stopping and starting track recommences audio output.  Mac book Pro Lion 16gb ram

    My audio stops outputting after a few songs in a playlist - itunes says its still playing, stopping and starting track recommences audio output.  Mac book Pro Lion 16gb ram.  Can be any song, any time, same song will play if I select it again.  Bit of a bummer itunes is the main thing I use (macbook pro jukebox).

    Most likely culprit is your Lacie drives which are notorious for flaky power supplies which cause just the sort of erratic behaviour that you describe. Have had similar issues myself. Lacie has been good about replacing my power converter-- twice. If you have seven of them, good luck finding the bad one or more. Like I said, the behaviour is erratic. Sometimes it'll work sometimes not. I can't comment on Samsung drives because I've never used them and have never heard anything about them. Same with Softraid. Why not just use Disk Utility. Sounds like you're ready for an external hardware raid. This will be much faster, much more reliable, and may even be cheaper than seven firewire drives. Check out G Tech, and Maxx Digital for starters.
    Best of luck
    Terry

  • Flash CC  sound files not playing

    I have a mp3 file on a layer.   I stop the fla file abuout 20 seconds in, but when I click on the play button to continue, the mp3 files starts from the beginning, not from the current location.  What do I need to change so the sound file will play from its current location?  Thank you.

    Rob,  I tried your recommendation,  it still will not sync.   I'm in the middle of my fla, and when I start from (ex. keyframe 500), the mp3 plays from the beginning (keyframe 1).  This issue is intermittent.  Some fla I have no issue, then others this problem happens.I end up using an older version of flash to do most of the work, then I complete the finishing parts in Flash CC.

  • Importing CD to Artist folder\Album folder\file with track number and name:

    I have a problem then importing my cd’s to my harddisk using iTunes.
    On my previous pc I got what I want, Artist folder, Album folder and file with track number and name:
    e.g.
    D:\My Music\B.B. King\Blues On The Bayou\01 Blues Boys Tune.mp3
    D:\My Music\B.B. King\Blues On The Bayou\02 Bad Case Of Love.mp3
    D:\My Music\B.B. King\Blues On The Bayou\03 I'll Survive.mp3
    But now I get:
    D:\My Music\Compilations\Blues On The Bayou\01 Blues Boys Tune.mp3
    D:\My Music\ Compilations \02 Bad Case Of Love.mp3
    D:\My Music\ Compilations \03 I'll Survive.mp3
    In iTunes my settings are Edit -> Preferences -> Advanced: iTunes Music folder: D:\My Music and checkmark in both: “Keep iTunes Music folder organized” and “Copy files to iTunes Music folder when adding to library”.
    My version of iTunes is 8.0.1.11
    Thanks in advance
    Peter

    It will depend on the album. Gracenote considers anthologies, a collection of tracks by the same artist taken from different albums, as a compilation. In iTunes the compliation setting should really only be applied to a collection of tracks by different artists.
    tt2

  • In Photoshop Elements 12, is there a way to batch process all photos in a file with 'Auto Tone' and save the changes?

    In Photoshop Elements 12, is there a way to batch process all photos in a file with 'Auto Tone' and save the changes?

    Thank you, that was perfect!
    Yoni

  • "File with specified name and version number already exists. Result code= -48."   ...????

    Recently I have been getting this error message when I try to record an audio track in Logic... "File with specified name and version number already exists. Result code = -48."  WHAT IS THE PROBLEM?????? It's making me furious!

    Hi
    As the message says, there is a file at the recording directory that has the same name:
    http://support.apple.com/kb/ht1618
    Try changing the name of the track (this sets the filename in later versions of Logic 9
    CCT

  • Ok.  I hope someone can answer my question.  I am new to photoshop.  I need version cs4 in order to work with a designer and printer on some logo work. I've tried to download it but it just gives me individual files with no installer and nothing - includi

    ok.  I hope someone can answer my question.  I am new to photoshop.  I need version cs4 in order to work with a designer and printer on some logo work. I've tried to download it but it just gives me individual files with no installer and nothing - including the adobe "instructions" seems to work.  How can i get this software in a downloadable format? is it actually free - I'm assuming it is...  Hope someone knows the answer to these questions...

    The download itself is free and is valid for 30 days only.  After that, the software ceases to work.
    CS4 is pretty old, no longer sold and no longer supported by Adobe.  It's also not compatible with many modern OSes.
    Why do you have to work with such an obsolete version of Photoshop?
    What kind of "designer" uses it?

  • Downloading .xls file with multiple rows and Columns

    Hi ALL,
    I need to genarate .xls file with multiple rows and and Columns and sent as an email.Since our customer having Problem with .CSV files need to genarate .XLS file.
    Please do the needful.
    Thanks
    Madhu

    Hi Madhu,
    You might also consider using Excel Spreadsheet XML as the target structure (namespace is urn:schemas-microsoft-com:office:spreadsheet).  When you double-click the resulting xml on a PC it automatically opens with Excel. So, users don't see a difference.  It will open up a lot of options with formatting including creating multiple worksheets if you wanted to.  Best of all you can stick with XML.
    See my response in this thread:
    Re: Convert XML data into XLS 
    Thanks,
    -Russ

  • Can I add the Play/Pause and Mute functions to image buttons

    A custom skin that was created to wrap around a Captivate
    movie we are creating does not include the playbar, but does have
    both a Play/Pause button and a Mute button, both of which are
    normally located in the playbar. We want to create custom image
    buttons for these actions and assign the Play/Pause and Mute
    funtions to them. Can anyone suggest how we might do this? I
    suspect that the answer lies in creating Javascript that will
    accomplish these funtions. Any suggestions would be appreciated.
    Thanks.
    JazzzAl

    Does anyone know if it's impossible?

  • Control 2 macs with 1 keyboard and mouse

    I have two iMacs, 27 inch 10.7 and 24 inch with 10.6. Side by side. The two communicate wirelessly using Apple Wi fi.
    I want to use one keyboard and mouse for both.
    I have downloaded "synergy" on both computers, however, attempts to control both have failed.
    I know that Apple screen sharing is an option, but I would prefer to use "synergy" or a similar program.
    (I vaguely recall controlling both computers in the past, but cannot recall how I did it.)
    Help? Control two Macs with one keyboard and mouse. That is my goal.
    Thanks.

    Try the software Teleport from Abyssoft. http://www.abyssoft.com/software/teleport/
    I just installed Teleport on Macbook Air and Macbook Pro and am now working on both with a single wireless keyboard and glidepad simply by dragging mouse from one screen to the other.

  • Every time I open Mozilla Firefox, there is an annoying sound that won't stop, and it sounds kind of like pac man. I t won't stop, and I have no idea where it is coming from. I have tried everything. Any suggestions on what I should do?

    Every time I open Mozilla Firefox, there is an annoying sound that won't stop, and it sounds kind of like pac man. I t won't stop, and I have no idea where it is coming from. I have tried everything. Any suggestions on what I should do?
    == This happened ==
    Every time Firefox opened
    == I opened firefox today, and it won't stop.

    It's just the Google homepage tribute to Pacman turning 30 today. A playable game starts up automatically, use the arrow keys to move Pacman. It's fun!
    You can get Ms Pacman to appear in that game by clicking the "insert coin" button twice and using the WASD keys to move :)
    You can also just change your homepage to something other than google until tomorrow.

  • When I am open file with adobe Pro and reader the resolution in my computer failing, change the resolution from 1920x1200 to 800x600. my video card is nvidia quadro 2000. w7 & 32 bits

    when I am open file with adobe Pro and reader the resolution in my computer failing, change the resolution from 1920x1200 to 800x600. my video card is nvidia quadro 2000. w7 & 32 bits

    Hi fabiangs,
    I'm not sure that I follow. Are you saying that when you open a PDF file in Acrobat or Reader, that the display resolution changes automatically on your system?
    What version of Acrobat/Reader are you using? Do you see this same issue in other files/applications?
    I look forward to hearing back from you.
    Best,
    Sara

  • Volume buttons and mute button don't function in Windows 8 64-bit

    Almost funny, I also have installed Windows 8 64-bit on my ThionkPad SL500 (clean install). I have read other people complaining about "Volume buttons and mute button don't function". This is exactly the same problem I have. I have found no exact procedure about what software to install to make this work. Instead people refer to other threads that often end in some desert... So, does anyone (Lenovo?) have a clear answer on what software to install (and links to those drivers please...) :-? And, yes, I have tried installing different software packages by following threads, but nothing has worked just yet... So, clear instructions / links, please :-)
    Thanks,
    Niels

    I recently found this information on the micorsoft troubleshooting website and thought of your post, not sure if you had found a solution but hopefully it is helpful.
    My keyboard volume controls suddenly stopped working
    If the volume controls on your keyboard stops working, check the Human Interface Device Access service on your computer to make sure it is set to Automatic.
    In the Start menu, type View local services.
    From the Search Results list, select View local services.
    In the Services dialog box, locate Human Interface Device Access. Make sure the status is set to “Started.”  If it is not started, click Start the service.
    Right-click Human Interface Device Access and select Properties.
    On the General tab, in the Startup type, select Automatic, and then click OK.
    Thank you for being a part of the Lenovo Family,
    Catie
    Did someone help you today? Press the star on the left to thank them with a Kudo!
    If you find a post helpful and it answers your question, please mark it as an "Accepted Solution"! This will help the rest of the Community with similar issues identify the verified solution and benefit from it.
    Donate KUDOS and Click "Accepted Solution"

Maybe you are looking for