Sound Class in AS3

I am still learning AS3, and I was woking with sounds. This
was to be used to stop the cound assigned to the channel1 var. When
I click the button the sound is just muffeled a bit, but does not
stop playing. Does anyone know it there is an issue with flash
running in Windows Vista?
Here is the code:
//Stop Function
function stopClick(evt:Event):void{
channel1.stop();
bStop.addEventListener(MouseEvent.CLICK, stopClick);
Thanks

I figured it out. When I added the soundLoaded function, I
thought I deleted the .play() and head of my code. Now it looks
like this, and works.
//Creates a var musicURL and assigns it the background
music.mp3 location name
var musicURL:URLRequest = new URLRequest("background
music.mp3");
//Creates a var sndMusic and points it to the musicURL
location
var sndMusic:Sound = new Sound(musicURL);
//Creates a SoundChannel var
var channel1:SoundChannel;
//Plays the sndMusic and assigns the soundChannel to channel1
function errorMsg(evt:IOErrorEvent):void {
trace("The sound could not be loaded");
sndMusic.addEventListener(IOErrorEvent.IO_ERROR, errorMsg);
function soundLoaded(evt:Event):void {
trace("Sound Complete");
//Plays the sndMusic and assigns the soundChannel to
channel1
channel1=sndMusic.play();
sndMusic.addEventListener(Event.COMPLETE, soundLoaded);
//Stop Function
function stopClick(evt:Event):void{
channel1.stop();
bStop.addEventListener(MouseEvent.CLICK, stopClick);
//Start Function
function playMusicClick(evt:Event):void{
channel1.stop();
channel1=sndMusic.play();
bPlayMusic.addEventListener(MouseEvent.CLICK,
playMusicClick);
Thanks. I hope this will be useful for who ever else make the
same mistake I did.

Similar Messages

  • Looking for information about AS3 sound classes in "audio" wrong places?

    I'm looking for in depth information about ActionScript 3.0 sound classes. No matter where I search I continually encounter the same sort of kindergarten level descriptions, which never teach more than what we can readily glean from Adobe's documentation. Someone must know where there a discussion that really gets to the heart of the matter.
    I've read Adobe's LiveDocs on the Sound, SoundChannel, SoundMixer, SoundTransform classes. Indeed, they provided me enough guidance to create my own streaming MP3 player, with volume, pan, my own custom mono mix, http request, a preloading animation, and peak meters ...
    Here's an example (in the last statement of the following code) where I understand the end effect, but I fail to comprehend what happens at the compiler level:
    var currentSoundSource:Sound = new Sound();
    currentSoundSource.load(new URLRequest("http://www.mySite.com/myRecording.mp3"));
    var audioChannel_01:SoundChannel = new SoundChannel();
    audioChannel_01 = currentSoundSource.play();
    Unfortunately the class definitions in LiveDocs are quite terse, and they're seemingly incomplete with respect to:
         •     advice on best practices
         •     a thorough coverage of class to class interactivity
         •     a description of exactly how audio streams/plays into channels
    ... and in certain cases it appears that Adobe's descriptions are not fully accurate.*
    Regarding best practices, at first blush I'm sure everyone ponders over the fact that SoundChannel and SoundMixer have a stop method while the Sound class does not.
    One assumes that this surprising design must bear some advantages. If so,  what are they? Where are the analog sound mixer analogies? What would be the disadvantage of a sound class with a stop method ...  particularly when they have their own play method?
    Where are the discussion of these concepts? (Even if Adobe hired the wrong guy to write its sound classes, there should be some follow through that thoroughly explains the existing situation.)
    Phrankie
    * Here's an instance where the docs appear to be partially in error. (Is "and play" mistakenly included in the following?)
    "The Sound class lets you lets you create a new Sound object [and] load and play an external MP3 file into that object."
    ... uh, mmmmmm ... we play an MP3 into a sound class object?
    Wouldn't it be more accurate to say the following:
    A soundChannel can receive the audio data from a sound class object. We can play a sound object into an SoundChannel and manipulate it by altering the SoundChannel's soundTransform property, and we can stop it with the SoundChannel's stop method. 

    check everything you can find written by tinic uro.  this will get you started:  http://www.kaourantin.net/

  • About playing dynamic generated sound using Sound class

    Dear sir:
    The live doc of Flex 4 says:
    In Flash Player 10 and later and AIR 1.5 and later, you can also use this    class to work with sound that is generated dynamically.    In this case, the Sound object uses the function you assign to a sampleData event handler to   poll for sound data. The sound is played as it is retrieved from a ByteArray object that   you populate with sound data.
    and i read one article(the following link)
    http://www.kaourantin.net/2008/05/adobe-is-making-some-noise-part-2.html
    it said: The Sound class only support 44100 sample rate,32 bit,2 channel sound data, is that true?
    Then if i get one ByteArray( 8000 sample rate,16bit,1 channel), how can i modify it to let the Sound class play it?
    thanks..

    Worked perfectly.  Thank you thank you!
    Jen

  • Sound class

    Hi everyone. I'm creating an audio player which will receive
    xml information from a server and play the requested sone. I have
    all that set up. The only problem I'm having with is creating the
    progress bar while the sound is streaming. What happens is when the
    audio player is opened, the song starts playing because of the
    streaming property that I set in the actionscript, but the progress
    bar doesn't show up until the song is fully cached on the user's
    machine. So the effect is you don't see the progress bar when the
    audio player opens and the song plays. Instead the progress bar
    will appear a couple of seconds after the audio player starts
    playing. I've put the project up on my site, so you can take a look
    at it and see what I'm talking about,
    www.mark-yieh.com/airspun/newaudioplayer.html. If you know how to
    fix it please let me know. It will really be appreciated. Thanks.
    I've looked at all the event handlers in the sound class, but none
    of them let's me gather information from the sound file until it's
    fully loaded. For example, with the MovieClipLoader class, there's
    an onLoadInit handler and an onLoadStart handler and an
    onLoadProgress handler, but there's none for the sound class. Is
    there another solution?

    if you're attempting to get the sound.duration before it has
    loaded, then you'll find that this will only return the number of
    seconds downloaded so far. sound.position should work okay though.
    check out the comments in
    livedocs
    for sound duration for some handy ways to approximate this
    property during streaming.

  • Sound class pause

    Hi i have a flash presentation, which has a pause and play
    button.
    the pause button pauses my movie fine, except i have voice
    sound as a sound class, the sound starts to play, but i can not get
    it to pause or stop
    any ideas what i need to do?
    i have the following code

    no, your code above is not correct: your onRelease functions
    are written as such to be placed directly on your button objects
    and not on the root time line; additionally, the function
    volAdjust(), which is the function responsible for controlling your
    sound, is not present in your code at all.
    to fully understand what is going on, take five minutes to do
    this:
    1.) open a brand new flash document.
    2.) import a sound to your library ( file > import >
    import to library ), open your
    library ( f11), right-click on the sound inside your library
    and select linkage,
    check export for actionscript, make sure export in first
    frame is checked, and
    then enter, newWelcome , into the identifier text field.
    3.) draw a rectangle on stage and convert it to a movieclip
    (f8) - name it whatever you wish.
    4.) with the newly created movieclip selected, go to your
    properties inspector
    and enter the string, btnPlay , into the instance name text
    field.
    5.) open your library ( f11) and drag another instance of the
    movieclip you just
    created onto the stage.
    6.) with the newly dragged out instance of your movieclip
    selected, go to your
    properties inspector and enter the string, btnPause , into
    the instance name text field.
    7.) make a new layer above the one you have working in and
    name it actions.
    8.) lastly ,copy and paste the code i sent you into the first
    frame of the layer
    actions. (note: your movieclips, btnPlay and btnPause,
    should be on the first
    frame of your second layer ( the layer beneath your layer
    labeled actions ).

  • Why Sound Class is greyed out?

    Hi, there
    I am trying to assign a sound class, but found it was greyed out. I'd appreciate if someone could help me to find a way...Thanks!

    I think you're right. The file I was working on was originally in AS2...Thanks a lot!

  • Sound class help?(oop)

    hey,
    i have got all my public vars for sound class but im having trouble on how i would execute them because i normal would use event listener but its OOP lol so how do you get that functionality :/
    ---code in star.as file:
    package
        import flash.display.MovieClip;
        public class star extends MovieClip
            public var my_sound:MySong = new MySong();
            public var my_channel:SoundChannel = new SoundChannel();
            public function star()
    thanks everyone

    dont worry i learnt oop and made my own class here it is if anyone has the same problem!
    Code:
    package
        import flash.display.MovieClip;
        import flash.events.MouseEvent;
        import flash.media.Sound;
        public class SoundClass extends MovieClip
            var sound = new Sound  ;
            var mySound:MySong = new MySong  ;
            public function SoundClass()
                mySound.play();
    Hope this helped somebody else

  • Automatically generated (Sound) classes

    Hi all,
    Quick summary:
    I'm trying to compile a SWC file with a lot of assets in it in an as easy possible way. "Easy" for a not so technical end user, not perse the way to acchieve that goal. Goal is to streamline a process to generate SWC files with as little possible tech for the person doing it.
    So, sort of like  manually doing:
    * Import files into Flash
    * For each library item select "Export for actionscript" and have Flash generate the basic class.
    * Publish as SWC
    but without the Flash IDE and the possibly labourous process.
    Right now I'm trying to put an AIR project together that generates classes based on a file list. The classes can than be added to a Flash Builder library project to generate a SWC file from it (copy in finder, check classes in Project properties, done)
    I can generate the classes for graphics like below. Such a class can then be instantiated from within the host application.
    package
              import flash.display.Bitmap;
              import flash.display.MovieClip;
              public class __0038_asset extends MovieClip
                        [Embed(source="assets/__0038_asset.png")]
                            private static const gfx:Class;
                        public function __0038_asset()
                                  super();
                                  addChild( new gfx() as Bitmap );
    Allthough this adds another level to the display list (which looks kinda sloppy to me), it works.
    However, for this to work for sound files I need to create a class implementing all possible methods and properties of the soundclass and handle the events and such. There is no way to extend Sound and then do something like you would/can with graphics.
    This is what I got:
    package
              import flash.media.Sound;
              import flash.media.SoundLoaderContext;
              import flash.net.URLRequest;
              public class _000_cover_hotsp_authormp3 extends Sound
                        [Embed(source="assets/000_cover_hotsp_author.mp3")]
                        private var snd:Class;
                        public function _000_cover_hotsp_authormp3(stream:URLRequest=null, context:SoundLoaderContext=null)
                                  super(stream, context);
                                  var mySound:Sound = new snd() as Sound;
    But that aint gonna work ofcourse.
    Does anyone know if there is a way to get to the format the Flash IDE generates the classes with?
    Thanks in advance.
    Manno

    Wel, here's the answer. Must have read it once since it is in the moock book, but stubled across it on the interwebs at: http://blog.nightspade.com/2010/02/01/embedding-asset-at-compile-time-in-pure-as3-project/
    For images use:
            [Embed(source="assets/Frog&Stranger02_03-titelblad_height_1024px 2.jpg")]
              public class a_A2BA79B5_CE46_F942_1AB2_CC26D8F7FCC8 extends Bitmap
                        public function a_A2BA79B5_CE46_F942_1AB2_CC26D8F7FCC8()
                                  super();
    and for sounds:
              [Embed(source="assets/000_cover_hotsp_author.mp3")]
              public class _000_cover_hotsp_authormp3 extends Sound
                        public function _000_cover_hotsp_authormp3()
    Now, lets review some code to see if I can apply this elsewhere too

  • Performance problems with external sounds and Sound class

    I'm using Sound & SoundChannel classes to load and play external MP3s and I'm seeing terrible playback performance on my 3G phone. Audio starts out ok, but will gradually get more and more choppy and eventually crashes the app. The MP3s themselves are typical sizes, 2 - 6 MB and of various types (VBR, CBR).
    On top of that, when the phone gets locked (with the app still running), the audio sputters and stops completely. When I unlock, it begins where it left off. Anyone else seeing this?
    My code is pretty standard:
    private var soundPlayer:Sound;
    private var soundChannel:SoundChannel;
    public function load(url:String, playNow:Boolean = true):void {
      if (soundChannel) {
        soundChannel.stop();
      soundPlayer = new Sound();
      soundPlayer.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
      soundPlayer.addEventListener(ProgressEvent.PROGRESS, onProgress);
      soundPlayer.addEventListener(Event.ID3, onID3);
      trace('Loading new stream: '+url);
      var request:URLRequest = new URLRequest(url);
      soundPlayer.load(request);
      if (playNow) {
        this.isPlaying = true;
        soundChannel = soundPlayer.play();
        soundChannel.addEventListener(Event.SOUND_COMPLETE, onSoundComplete);

    this is from another forum (http://discussions.info.apple.com/thread.jspa?threadID=2542931&tstart=0&messageID=12106188 ):
    "I've spoken to the developers of of couple of these apps, and they've all said it's a memory fragmentation/low memory condition.
    Restart the phone. Don't just turn it off and on, but restart it.
    Hold the on/off button and the home button down like you were going to turn it off. When you see the swipe to turn off message, keep holding the buttons down.
    In a few seconds the screen will flash, and then go dark.
    Now it's really off.
    Turn it back on (restarting it). All should be well.
    The iPhone is really a computer. Performing a restart like this every  once in a while (weekly, bi-weekly) is a good idea, esp if you use  memory intensive apps."
    coop

  • Create Sound Spectrum in AS3

    I'm trying to create a spectrum display for microphone
    input/playback in ActionScript 3 but can't seem to get it to work.
    I understand that the SoundMixer class does not control dynamically
    created Sound objects, but surely there is a way around this! Has
    anyone done this or have any ideas on how to approach this problem?
    I can record and playback the sound using rtmp and net streams just
    fine, but can't manage to create any form of sound spectrum from
    this sound. I'm at a loss here...
    Any suggestions would be appreciated!!

    I have created the variable and set to 0.  However i'm not sure how to get it to add one when an item on the stage is clicked on??  What would this look like??  Any help would be great
    Thanks in anticipation

  • Classes in as3

    i use AS2 and wish to start using AS3, however i fid it confusied with CLASSES.
    is it possible to learn and use AS3 without classes?

    Yes, you can learn AS3 to a useable extent without learning how to create classes. Though you won't get far in any version of Actionscript without knowing how to use classes.  Even with AS2 you have likely been using classes all along without realizing it.  A MovieClip is a class, a Button is a class, a TextField is a class, and on and on...

  • How to use geturl using class in AS3

    i try this code (my class name is bAEForm)
    package {
          import flash.display.SimpleButton;
          import flash.display.Sprite;
          import flash.net.navigateToURL;
          import flash.net.URLRequest;
          import flash.net.URLRequestMethod;
          import flash.net.URLVariables;
        public class bAEForm extends Sprite {
            public function bAEForm() {
                var url:String = "http://www.google.com";
                var request:URLRequest = new URLRequest(url);
                var variables:URLVariables = new URLVariables();
    variables.exampleSessionId = new Date().getTime();
    variables.exampleUserLabel = "guest";
    request.data = variables;
    request.method = URLRequestMethod.POST;
    navigateToURL(request);
    I got error this error
    The class “bAEForm” msut subclass “flash.disply.SimpleButto” since it is linked to library symbol of that type.

    I got the solution but again facing some problem. When I go my scene (where I put my button), Automatically 2 browsers are open. I don’t need this. I need, when I press my button then browser should to be open
    Any suggestion
    package {
              import flash.display.SimpleButton;
              import flash.display.Sprite;
        import flash.net.navigateToURL;
        import flash.net.URLRequest;
        import flash.net.URLRequestMethod;
        import flash.net.URLVariables;
        public class bAEForm extends SimpleButton {
            public function bAEForm() {
                var url:String = "http://www.google.com";
                var request:URLRequest = new URLRequest(url);
                var variables:URLVariables = new URLVariables();
                variables.exampleSessionId = new Date().getTime();
                variables.exampleUserLabel = "guest";
                request.data = variables;
                request.method = URLRequestMethod.POST;
                navigateToURL(request);
    I got the solution but again facing some problem. When I go my scene (where I put my button), Automatically 2 browsers are open. I don’t need this. I need, when I press my button then browser should to be open

  • Importing classes confusion AS3

    I must admit, I don't know Actionscript 3.0 extremely well but I know my way around it and am able to get by as a designer.
    I'm just wondering if classes should ALWAYS be imported. The reason I ask is because sometimes I don't import classes but my Actionscript still works without any problems.
    Just wondering if anyone could shed some light on this please?
    Thanks

    Are you using custom classes? If so then all of the ones you use will be required.
    So suppose you have in your code:
    var myInstance:SomeClass = new SomeClass();
    Then at the top you should add
    import com.mydomain.somePackage.SomeClass;
    Or if you are using packages like TweenLite or such. Even if you have added that to your classpath and it works without the import statement, it would be a surprise if you move it to another machine that doesn't have that installed.
    And of course the best way to find out is to have a problem where something goes wrong. That is really all that separates the noobs from the "pros" -- we have made a lot more mistakes than you've even thought of yet!

  • Instantiating MXML class in AS3

    I have a simple MXML component:
    -- code -- 'MyClass'
    <mx:Canvas ... creationPolicy="none" ... >
      <mx:HBox id="innerPanel" >
        <mx:Canvas ... />
      </mx:HBox>
    </mx:Canvas>
    -- /code --
    I'm trying to instantiate this in AS3 as so:
    -- code --
    var myClass:MyClass = new myClass();
    myClass.createComponentsFromDescriptors(true);
    -- /code --
    myClass is created, but no children.  myClass.childDescriptors is empty.
    What am I doing wrong?
    thanx,
    rickb

    Unfortunatelly nothing of the above works when you have a chain of MXML's and AS's that are instantiating eachother. Not even the combination of all of the techniques mentioned earlier.
    I tried all of the above on the entire chain, and even placed callLater in the main canvas container but still creationComplete in MyMXML happens after callLater.
    I tried to be creative with the bellow pseudo pseudo code, I hope you get the idea.
    <MyMainCanvas>
    <script>
    onCreationComplete
    var myClass = new MyClass();
    addChild(myClass)
    callLater(doSomething)
    doSomething()
    // does nothing as none of the properties are available from MyMXML
    </script>
    </MyMainCanvas>
    MyClass extends Canvas
    function MyClass()
      var myMXML = new MyMXML();
      addChild(myMXML);
    <MyMXML>
    <script>
    onCreationComplete
       // this gets called after callLater in MyMainCanvas
    </script>
    </MyMXML>

  • List sound devices in AS3

    Is it possible to list Sound output devices on a system.  I'd like to be able to list Sound output devices and play a sound to more than one sound device at the same time.  I.e. Internal speaker and a USB headset.
    I know you can capture sound from multiple input devices using Microphone.names and Microphone.getMicrophone(index);
    Can I play the sound to multiple sound devices?

    It's really context. If you're on a website, you can't access a webcam or microphone at all unless the user allows you to in their preferences, and they are prompted when you do so.
    In an AIR application I would like these advanced techniques but as you pointed out yourself with the link, the way the OS handles device addressing under the hood can likely change, so they don't advise even a 'workaround' for choosing where to send audio.
    On the example you listed above, while you're free to implement things like that, is it really a good idea to have a user have headphones on while you still intend them to hear (headphone muffled) sounds coming out of the speakers? I'm not sure why you'd like a setup such as that other than clearly separating communication from the application. I never came across a need such as this however. If I can pay attention to a game and 30 people on a Ventrilo server at the same time perfectly well, I don't think users should expect to listen to both the speakers and the headset. That's just my $0.02.
    As it is now, you're free to tinker with Adobe Native Extensions to see what added behavior it can extend AIR to regarding a desktop application.

Maybe you are looking for

  • How to use FM:hrforms_call_pdf

    Sorry....I mean Function Module : HRFORMS_CALL_PDF.Now i got it....Previously i tried searching in google...They are giving description...But not even a piece of code for example....That's why i got confused...Sorry it's my mistake...i wrote it incor

  • Link an iPad to TV possible ?

    Is it possible with some wires or devices to see whats on my iPad in my TV ? And secondly ir yes, can i see all app or is there some restrictions on some apps ? Tyvm

  • DBMS_MVIEW.ESTIMATE_MVIEW_SIZE rows returned different that the count of..

    Hi, I have done the following... 1.Gathered table stats... SQL> EXEC DBMS_STATS.GATHER_TABLE_STATS('SCOTT','STRDET'); PL/SQL Procedure executed successfully SQL> EXEC DBMS_STATS.GATHER_TABLE_STATS('SCOTT','DETAILS_DET'); PL/SQL Procedure executed suc

  • Solman Road Map Issue

    Good Day, I have created the new Roadmap using the RMDEF/RMAUTH  and i want to use that Roadmap in one of my Projects in Solution Manager.I have selected the Same Roadmap in Scope of the Project in (Project Administration),But the Structure or Hierar

  • Multiple cuts from multicam sequence produce stacked video?

    Hey everyone, I don't know if this is by design or if I'm experiencing a bug. I have created a multicam sequence. I want to take multiple cuts from it, so I set my first in and out points and drag that over to my sequence. After that, I set new in an