Sound in AS3

flash.display.Loader has a nice function, 'loadBytes', which
takes a ByteArray as a parameter. Is there no way to load an mp3
from a ByteArray as well? The only method I could come up with
involved embedding the mp3s, which I hope to avoid, since I do not
feel like wrapping every mp3 that comes my way (it's a lot of
pointless work, and then the data can only be used in flash 9).
-jesse

this post seemed more lively:
http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?catid=581&threadid=1086327&en terthread=y

Similar Messages

  • Need help playing sound via AS3

    Hi all,
    First time I have tried playing a sound through AS3. I found an example from kirupa, but for whatever reason I can not get it to play the sound. I'm not getting any errors etc, and I have my .wav file inside the same directory as my .fla/.swf I have tried playing from inside the flash pro interface and from a personal webpage server.
    Is there something that I am missing? I just have a action layer with the below code inside the first from of the movie.
    var soundClip:Sound;
    function init() {
    soundClip = new Sound();
    soundClip.load(new URLRequest("mysound.wav"));
    soundClip.addEventListener(Event.COMPLETE, soundLoaded);
    soundClip.addEventListener(ProgressEvent.PROGRESS, soundLoading);
    init();
    function soundLoaded(e:Event) {
    soundClip.play();
    function soundLoading(e:ProgressEvent) {
    // preloader information goes here
    Any help would be great

    thanks for that kglad that solved that problem. what I am trying to do is play the sound 1 time for a session only. I'll have multiple pages that use the same .swf, I just want the sound to play 1 time when the user first visits and then not to play for all other requests.
    This is an example I found, to you does it look right? I'm not getting any errors, but I'm not getting the sound to play either.
    import flash.net.SharedObject
    //Use anything in place of "sounds"
    var so:SharedObject = SharedObject.getLocal("sounds");
    //Check if the sound has not been played
    //Use anything in place of "specificSoundPlayed"
    if(so.data.specificSoundPlayed == false)
    //Play the sound
    var snd:Sound = new Sound();
    snd.load(new URLRequest("my.mp3"));
    snd.play();
    //Set the shared object property so we know the sound was played
    so.data.specificSoundPlayed = true;

  • Best way to handle sounds in AS3

    I'm currently doing some game development, targeting iOS and Android devices using Flash Pro and AS3.  I'm doing my best to keep the code highly optomized and doing as much object pooling as possible. So far, I'm very pleased with how smooth everything is running on the devices.
    I have noticed that when the actual 'game play' starts up, there is often a short hitch the when any particular sound effect is called up for the first time.  After the first time its seems fine.
    I can only assume that the hitch in game play is Air loading up the soud file into memory (which is why it's hitching only on the first call). 
    I'm a bit of a novice when it comes to audio, but I'm wondering if there is a best practices when it comes to managing the various sound fx and sound tracks so everything plays smoothly 'without a hitch'.  har har.  Currently the sounds reside in my Library as exentions of the Sound class, and i just crate an instance of those classes at run time and .play() when i want to call them.
    Thanks ahead of time,
    -dis

    Yeah, I have thought about that, it just seemed like an awfully sloppy solution. I was kinda hoping for a non 'hack' method to get them properly loaded into memory- but if thats they only current way- then thats the only currenty way.
    -dis

  • Controlling Timeline sound in AS3

    Hello everyone,
    I have a timeline with a sound in it set to sync because I am
    scrubbing the main timeline....
    I now want to control the volume of the sound in the
    timeline..is that possible in AS3??
    sometime like : var my_globalSound:Sound = new Sound(stage);
    that of course doesn't work, but how would I get access to
    the sound set in the timeline...
    thanks!

    Thanks to all of you I was struggling with the same thing.
    The given code work perfectly for me.
    SoundMixer.soundTransform = new SoundTransform(0, 0); //volume, pan
    My issue: I am loading and external swf file(as3.0) wich have audio on timline and I want volume controller for that audio.

  • Fade Sound in AS3

    I have been trying for a while now to get sound to fade. Right now the sound plays using this in one frame:
    var applause:Applause = new Applause();
    var channel2:SoundChannel = applause.play();
    A couple frames away I tried this to get it to fade:
    var SoundFade = 1;
    var i = 0;
    do
    SoundMixer.soundTransform = new SoundTransform(SoundFade,0);// 1=vol, 0=pan
    trace("SoundFade "+SoundFade);
    SoundFade = SoundFade - .1;
    trace("i "+i);
    i = i + 1;
    } while (i!=10);
    Doesn't work. I understand from postings that AS3 is buggy with sound and TweenLite might be a better option so I have also tried this:
    TweenLite.to(channel2, 1, {volume:0});
    This gives me this error:
    ReferenceError: Error #1069: Property volume not found on flash.media.SoundChannel and there is no default value.
    at com.greensock::TweenLite/init()
    at com.greensock::TweenLite/renderTime()
    at com.greensock.core::SimpleTimeline/renderTime()
    at com.greensock::TweenLite$/updateAll()
    Can someone please help me with this? Very frustrated.
    -Kirk

    Here is how fading should be implemented using TweenLite. I tested this code and it works perfectly. You will need to accommodate this to your needs - for instance I loaded sound at runtime - just replace loading routine with instantiating sound from your fla library:
    var sound:Sound;
    var channel:SoundChannel;
    var sTransf:SoundTransform;
    loadSound();
    function loadSound():void
         sound = new Sound();
         sound.load(new URLRequest("sound.mp3"));
         sTransf = new SoundTransform();
         channel = sound.play();
         channel.soundTransform = sTransf;
         var timer:Timer = new Timer(2000, 1);
         timer.addEventListener(TimerEvent.TIMER, onTimer);
         timer.start();
    function onTimer(e:TimerEvent):void
         TweenLite.to(sTransf, 3, { volume: 0, onUpdate: updateChannel, onComplete: onFadeComplete } );
    function onFadeComplete():void
         channel.stop();
    function updateChannel():void {
         channel.soundTransform = sTransf;

  • Recording sound in as3...

    Hi All...
         Can any one tell me please, How to record sound for mobile devices and save those recoded files in local system in mp3 format using as3 and air?

    Hi bhargavi,
    I'm not sure if you can save sound files to the local system even with AIR.
    Some time ago I made a similar application, just for test, but I had to send the bytes to a server in order to be recorded. The idea at the time was to use a TTS system.
    I used this page to guide me:
    http://www.bytearray.org/?p=1858
    After googling a bit, I found this one with an example... this is probably what you want:
    http://www.addictivetips.com/windows-tips/microphone-free-adobe-air-mp3-audio-sound-record er/
    See if it works.
    Cheers

  • Need to play a runtime shared sound in AS3

    I am having a hard time playing a sound that was imported from a shared library of a second SWF file.
    On the shared library FLA, I have my sound's linkage properties set to:
    Linkage Identifier: MySound
    Export for Actionscript
    Export in Frame 1
    export for runtime sharing
    The Linkage Identifier is a simple identifier (MySound) with no .wav at the end, and no spaces.
    On the destination fla, I went to File -> Import -> Open External Library.
    I browsed for the shared library FLA, clicked it, and dragged the shared sound into the destination FLA library.
    On the destination FLA, I have the sounds linkage properties set to:
    Import for Runtime Sharing
    Sounds.swf is in the URL field.
    Now, for the Code that plays the sound:
    var mySound:MySound = new MySound();
    var myChannel:SoundChannel = new SoundChannel();
    myChannel = mySound.play();
    Flash gives me an error that says:
    ArgumentError: Error #2068: Invalid sound.
        at flash.media::Sound/play()
        at Player_fla::MainTimeline/frame1()
    What am I doing wrong?  Please help me.

    I'm curious, what *should* the crossdomain file say, and
    where should it be. I am looking at it now, and it says:
    <cross-domain-policy>
    <allow-access-from domain="*.domain.ca" />
    <site-control
    permitted-cross-domain-policies="master-only" />
    </cross-domain-policy>
    and it is at
    http://video.domain.ca/crossdomain.xml
    Is this right, or did we miss something?
    As a side note...I'm wondering if somewhere in my code, I am
    calling this wrong (this is the first time I have tried doing
    this). My code is attached.
    Thanks!

  • Working with Sound in AS3

    Ok I understand the structure of the new sound setup.
    But when I used this on a swf that I uploaded to a different
    site - the sound didn't work - I didn't have the option of loading
    separate files to the website so the URLRequest could find the
    sounds.
    Is there a way of embedding the files so that they are
    exported into the SWF.
    OR is it meant to be embedded and on this occasion there was
    some unknown error with SWF?

    you can import sound files into the flash authoring
    environment so they're part of the compiled swf. generally, this
    isn't desirable for mp3's because they are usually large files that
    delay the swf's initial load.
    and there's nothing wrong with your code. if that mp3 is in
    the same directory as the html that embeds the swf that contains
    that code, your mp3 will play.

  • Sounds in AS3

    I tried using this code-
    var soundReq:URLRequest = new URLRequest("Z.mpg");
    var woodblock:Sound = new Sound();
    woodblock.load(soundReq);
    a.addEventListener(MouseEvent.CLICK, pickUp);
    function pickUp(event:MouseEvent):void {
    woodblock.play();
    And got this error-
    Error #2044: Unhandled IOErrorEvent:. text=Error #2032:
    Stream Error.
    at a_fla::MainTimeline/frame1()
    Text
    Could someone point me in the right direction to make this
    work? Thanks!

    I answered my own question, for anyone else in this situation
    you have to use an MP3 file.

  • AS3: How to access and control embedded sounds in an external swf?

    I rarely use sounds in AS3/Flash. I am using Flash Pro CS6, but I can't seem to figure out how to access, control (play, stop, etc) sounds embedded in an external SWF loaded into the main SWF.
    It's easy to control them when embedded on the main swf. However, on an externally loaded SWR, I get all kinds of errors. For this app, I really need to embed them in the external SWF.
    I read several solutions, but none seem to work.
    I embed the sound an mp3 file called soundSegment1.mp3 using Flash CS6 import tool and then open the actionscript properties panel on flash to select the class name: SoundSegment1. Then I edit the class code and create a file called SoundSegment1.as and it's saved right next to my document class main.as in the same directory. The code of the SoundSegment1 class looks like this:
    package  {
        import flash.media.*;
        public class SoundSegment1 extends Sound
            public function SoundSegment1 ()
                // no code in here
            public function playSound()
                var soundSegment1:Sound = new SoundSegment1();
                var channel:SoundChannel = soundSegment1.play();
    Then, in my main.as, I have done several attempts to play this sound such as:
    var fileLocation:URLRequest = new URLRequest(SWFToLoad); loader.load(fileLocation); loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressListener); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeListener); loader.contentLoaderInfo.addEventListener(Event.INIT, initListener); 
    function initListener(e:Event):void // I also placed this code on the completeListener and it didn't work {      loader.content.soundSegment1.playSound(); // doesn't work.  }
    I get:
    Line XXX 1061: Call to a possibly undefined method playSound through a reference with static type flash.display:DisplayObject.
    or, I also read that I should be able to do something like this anywhere in the Main.as file:
    var theClass:Class = Class(loader.content.getDefinitionByName("SoundSegment1")); var theSound:theClass = new theClass(); theSound.play()  //doesn't work either.
    I also tried on the completeListener:
    var TheClass:Class = e.target.applicationDomain.getDefinition("SoundSegment1") as Class; var theSound:TheClass = new TheClass();
    theSound.play()  //doesn't work either.
    I get:
    ReferenceError: Error #1065: Variable SoundSegment1 is not defined. at flash.system::ApplicationDomain/getDefinition()
    I am stuck and I really need to get this to work. I would be genuinely grateful for your help.
    Thank you in advance for any help provided. I really need to get it to work, because I can't simply embed them in the main SWF or load them individually externally one by one.
    Thanks again!

    THANK YOU!
    I think your code may be over my head though. I think you are using an anonymous function which is not something I am familiar with (but I want to learn about if it's useful).
    I also don't know where the classS came from. I see that it's a parameter sent along with the event, but I don't really see where that came from.
    Someone at: http://www.kirupa.com/forum/showthread.php?305098-Playing-a-embedded-sound-in-an-external- swf&p=2658098#post2658098
    Is showing what seems to be an easier solution, but my problem there is I can't access the source file of the "child" swf....  ayayay.....
    I am going to tinker with your solution and see if it gets me anywhere. Thanks so much for your help again.

  • [AS3.0]SoundChannel.position≠Sound.length

    別の掲示板の引用で恐縮ですが、まさにこの問題に直面しています。
    http://www.flash-jp.com/modules/newbb/viewtopic.php?topic_id=7819&forum=8&post_id=38874#f orumpost38874
    上記サイトで書かれていますが、
    「 Firefox 2.0.0.14 & Internet Explorer 7.0/Windows Vistaで確認したところ、SoundChannel.positionプロパティの値がSound.lengthの値に達しないという問題が生じました。」
    の問題に対する、解決策、回避策などはございませんでしょうか。
    AS3.0+Vistaの環境では、mp3の再生に合わせてバーを伸縮させるスライダーようなものは作れない、なんてことはないと思うのですが・・・
    再生終了時のpositionの値がlengthの値と同じにならなくても、その終了した時の値が、再生前に分かれば問題ないのだと思うのですが、そのようなことは無理でしょうか。
    その他、何か情報がありましたら、ぜひよろしくお願いいたします。

    Thanks Andrei.
    But I really dont understand. You see, I am not too good (actually pretty bad) with Ationscript 3.
    Att.,
    Edwin
    I managed to get it to move each second though with this:
    var myTimer:Timer = new Timer(1000);
    myTimer.addEventListener(TimerEvent.TIMER, runTimer);
    myTimer.start();
    function runTimer(event:TimerEvent):void {
    trace("Hello");
    progreso.value = progreso.value+1;

  • Wav sound and frame rate problem

    I have a wav file sound that I'm using within a movie clip in
    the movie clip's timeline. When I test the movie from within Flash
    (command-return), everything works great. When I publish and view
    online, here's what happens.
    If I click a button to move to another frame in the movie
    while the sound is playing, the frame rate speeds up and the movie
    gets a "fast forward" look to it until the sound ends. If I click a
    button when the sound is not playing, everything is fine. Am I
    missing something in the publish settings? Do I need to stop the
    sound in AS3 on the CLICK events (and if so, how)?
    Thanks,

    You will have to use Compressor...and the Advanced Conversion settings...DVCPRO HD 720p24. But you will also need to go into the FRAME controls in the INSPECTOR and make sure that you make it progressive and that you changes all the settings to better or best. This means that it will take a while, but it will look better.
    Shane

  • Fade in/out library sound?

    hi all
    having real problems finding anything about fading in and out sound in flash, have searched for 3 days now and found mostly as2 related articles, wondering if you could help me out?
    i have the following
    var myintSnd:introSound;
    var sndintChannel:SoundChannel;
    myintSnd = new introSound;
    sndintChannel = myintSnd.play();
    just wondering how i would fade in this sound using as3?
    so that i could maybe reverse the solution, so that on buttonclick the music will fade out ready for the next frame
    Ive heard it can be done using timers that increment the volume over time, but havent had much success with them, hope you can help, would much appreciate it
    thanks
    fonzio

    hi and thanks for the reply
    yes i used audacity to fade the sound in, so that worked, however i need to have the sound keep looping until a user clicks a button on which i need it to fade out,
    can you help?
    thanks
    fonzio

  • Simple sound object and TotalBytes

    Hello,
    I built this simple sound object below:
    var s:Chimes = new Chimes();   // Chimes class via chimes.wav in library
    s.play();
    //trace(s.bytesTotal);   this works fine but comented out for now = 2912 bytes
    s.addEventListener(Event.SOUND_COMPLETE, done);
    function done(e:Event)
    trace(s.bytesTotal);  // this does not trace at all
    To me I added a listener to the s instance. I am waiting for the
    s instance to finish loading the entire sound  s.
    I can't figure out why the trace displays nothing.
    Have I attached the wrong event to look for when
    the sound completes loading?
    Thanks,
    Jim

    How can this NOT work????
    //Create an instance of the Sound class
    var soundClip:Sound = new Sound();
    //Create a new SoundChannel Object
    var sndChannel:SoundChannel = new SoundChannel();
    //Load sound using URLRequest
    soundClip.load(new URLRequest("chimes.wav"));
    //Create an event listener that wll update once sound has finished loading
    soundClip.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
    function onComplete(evt:Event):void {
    //Play loaded sound
    sndChannel = soundClip.play();
    Taken directly from:
    http://flashspeaksactionscript.com/loading-external-sounds-using-as3/
    I hear nothing.

  • Sound Object and Media Display

    I'm creating a music player that uses xml generated from a
    database to load a song. One of the attributes of the xml is the
    path to the mp3 file. The attribute is stored in a generic object
    and is then passed as a function parameter. There's a lot of
    information i'd like to use from the id3 tags but the only object
    that supports them is the Sound object. I need the files to stream
    so they aren't cached onto the local system and have a media
    component to control playback.
    If I create a sound object and use the file path parameter in
    the loadSound method I can grab the id3 tags but the media
    component doesn't have control of playback and the files are
    cached.
    mySound:Sound = new Sound();
    mySound.loadSound(pathparam, true);
    If I just load the file path into the media component it
    starts playing right away and streams with the lovely built-in
    progress bar but I can't seem to access the id3s.
    mediaComponent.setMedia(pathparam, "MP3");
    Is there a way to load an actual Sound object into the media
    component so they will stream but also have access to the id3s?
    Thanks in advance for any tips!

    How can this NOT work????
    //Create an instance of the Sound class
    var soundClip:Sound = new Sound();
    //Create a new SoundChannel Object
    var sndChannel:SoundChannel = new SoundChannel();
    //Load sound using URLRequest
    soundClip.load(new URLRequest("chimes.wav"));
    //Create an event listener that wll update once sound has finished loading
    soundClip.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
    function onComplete(evt:Event):void {
    //Play loaded sound
    sndChannel = soundClip.play();
    Taken directly from:
    http://flashspeaksactionscript.com/loading-external-sounds-using-as3/
    I hear nothing.

Maybe you are looking for

  • How to use change document object ?

    Friends, I am learning to use the Change Document object for one of my Z table. I have created a change doc object using SCDO. I have now written a test report in which i am issuing the SELECT statement for fetching old and new values from the Z tabl

  • MaxDB going offline after log recover

    Hello, I've got a problem with my standby instance. I would like to import data into standby instance from autolog files generated by master instance. I am trying to use dbmcli tool + its utility session. My problem is, that after data recovery my da

  • Need for Custom Container

    Hi all, I have read that you use Custom container class for oops alv. But i have not found an answer as to  why do we have to use the class. Can't we just use ALV class only (Cl_gui_alv_grid) ?. Regards Varun

  • Video conferencing between iChat 4.0.2. and AIM Pro (on PC)

    My girlfriend lives in Iowa and just bought a brand new Dell with Windows Vista. She has AIM Pro and I'm wondering if it is possible to video chat with her, using my new macbook and her new Dell. I've read many posts about this and there doesn't seem

  • Subscription Service Product Activation Process

    If the subscription service for Adobe InDesign CS5.5 is purchased how often does the product activation process occur, every time the application is launched, or once a month after the subscription payment has been processed? In other words, if I am