Embedding sound in swf

Hi Guys,
I'm trying to make a drum beat in actionscript 3 using flex
builder 2. I have imported the sound using this code:
private var snd:Sound = new Sound();
private var req:URLRequest = new URLRequest("cymbal.mp3");
snd.load(req);
and initialize a timer with the code:
private var tempoTimer:Timer = new Timer(1000,0);
I then trigger the sound every 4 seconds by
if (tempoTimer.currentCount == 4) {
snd.play();
tempoTimer.reset();
tempoTimer.start();
I can hear the sound file play, however it doesn't keep a
consistent beat, basically the time between the beats aren't four
seconds, it varies. It's easier to hear if you change the interval
to 100 milliseconds.
So I've assumed that it needs to be preloaded by containing
the sound file in the swf. This can be done in flash using linkage,
however i'm not sure if this is possible in flex builder. Is there
a way that I can extract the code that flash creates with its
linkage system?
Any feedback would be great.
Cheers,
Paul

Thanks Sujit,
I got it working. I think I my problem was that I wasn't
importing the right files. I used the code from here:
http://livedocs.adobe.com/flex/3/html/help.html?content=Working_with_Sound_05.html
Thanks again.

Similar Messages

  • 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.

  • How do I get a handle on embedded sound files?

    From the Sound Class information, it says to use the SoundMixer Class to handle embedded Sound Files.  I have two sound files embedded, that I have setup in 2 separate layers, starting at frame one in the main timeline.  I needed to do this so I could see the wave files, and coordinate text with the waves.  I do not want to load these files into the .swf file at runtime using URLRequest.  How do I get a handle on those as they exist, to make each controllable by separate volume and mute controls for each sound?
    This will be a challenging question, because, "it can't be done" doesn't work for me.  I managed to create a way to use an external classfile to control the main timeline, the ROOT timeline, without having to create a sub movie to root.  I can use my component to call play(); as though it were in code in a frame.  But it isn't, it's in an external classfile.  I passed root to the classfile and told the classfile to think of it as a movieclip - that put the handle on it.  I tried similar way with root as a Sound, but that isn't detailed enough - I need to get a handle on the frame that contains the embedded sound file.  I embedded, attached it, using the properties view for the frame.
    I've attached, or whatever you want to call it, these sound files to a frame, and this frame is or should be attached to the layer I've created.  So, under the assumption that the ROOT has everything attached to it in some manner (it is after all the foundation for the COM), the stage of the root contains the visual components, so ROOT has to have the layer objects attached to it, which should have the frame objects attached to the layers.  I have two layers that each have a .wav file attached to frame one.  Somehow Flash keeps track of that - I want to know how Flash does it so I can read what flash reads.
    If this seems redundant, it probably is.  I want to paint the best picture I know how so I can get detailed feedback.  Please, if you have questions ask them so we can clarify, and get this resolved!  Thanks for reading!

    lol.
    ok, it can be done.  keep working on it.

  • Damsel In Distress: Embedding Sound Clips in Fillable Forms

    I embedded sounds (WAV files) in my professional 7.0 pdf with both the sound tool and the button tool. I also customized these with my own icon (JPG and PNG images). PROBLEM: once I open my pdf as a fillable form to add comment boxes, all the sound clips disappear, both icons and sounds. QUESTION: how can I embed sounds in my fillable forms? Thank you!

    Thank you, but without LiveCycle Designer where does Acrobat allow me to create a fillable form that my user can submit data back to me via email. Again, I am embedding my sound files in Acrobat, but once I select the Advance Menu|Forms|Make Form Fillable in Adobe Designer, it automatically opens LiveCycle Designer and my embedded sound files disappear. Any other suggestions are welcomed!

  • Acrobat Pro: Making timecode visible in embedded sound files?

    Hello.  I teach music history courses.  For copyright purposes (i.e., to prevent music theft), I am embedding sound files in PDFs for student use.  Some of my commentaries have timing cues (e.g., Horns enter at 3'38"), but I've not found a way to make the timecode visible to the students.
    Time codes are, of course, a standard feature on most music players (iTunes, Quicktime, WMP, etc.), as well as on many Flash players.  It seems reasonable that the media player in Acrobat should have a similar feature, even if disabled by default.  But if it does, I have been unable to locate or enable it.  Does such a feature exist on Acrobat?
    If not, does anyone have a recommendation for a possible alternative?  Thanks.

    You do know that as of Acrobat 9.0 you are able to include Flash Movies in PDFs. Now as to how that works I couldn't tell you as I haven't used Flash much even though I have it as part of Studio 8.

  • Web and embedded sound in PDF

    Hi,
    Made a posting in the Windows group but no one seems to know anything about the item.
    I found the possiblity to embed sound in a pdf very accurate to a project I´m working on (example pages from a teaching material in languages) and embedded the corresponing sound (from a CD that is included with the book) and put a nice poster image to start playing. Those pdf:s was then published on the net. It seems to work fine on every PC I´ve tested but the customer has a Mac and when the pages where opened there was no poster or possibility to listen to the sound file. I´m not sure what OS he is using but is there any problems related to this that anyone here can enlighten me.. ?
    Most thankful for any help.
    My best
    Michael

    First of all, I'm not that familiar as a user of Acrobat Pro. But as its included in my CS4 suite I checked it out by "intuition" and as I understood it the "embed-media" feature is a rather new one. Anyway, how I did it is staight forward from the interface. You insert at media type (in my cas a mp3-file) and optional you can use a "poster" as a trigger/button to play the file. Both the sound file and the image is included in the pdf-file.
    Anyway, it would be helpful to know if you can play the sound filde from your Mac. Most helpful would be if anyone knows any limitations connected to my pdf with embedded sound in terms of the average web-user, and especially those running on Macs.
    You don't need to download the file, just open the URL http://www.imatri.se/lab/Prosim/pdf/prosims8.pdf. The page displayed is an excert from a language material in swedish but regardless this: Everything is OK if theres an image of an CD, a playbutton and some text in swedish ABOVE the chapter name "1 Ahoj". A click on that image will play the sound.
    Please let me know how it looks and again I ask anyone who knows about possible limatations to use this kind of docs.
    My best
    Michael

  • Embedded Sounds Cut off Early

    This is a repost of a question I oriinally posted here http://stackoverflow.com/questions/11321441/embedded-sounds-cut-off-early .
    I figure this is one someone who knows the compiler part of Flash intimately will need to answer (if there is a good answer--if not I probably need to file a bug report).
    I have a combined Flash Builder/Flash Pro project. Because of the hassles involving in maintaining sound assets on the timeline, my sounds are all embedded into Class files, like:
    [Embed (source="/mp3/Welcome_01_V.mp3", mimeType="audio/mpeg")]
    private static const WELCOME_1:Class;
    These files are then referenced by the base Classes for the symbols that need them, embedded for Actionscript on Frame 10 (because the second frame label is on Frame 10 to give space for you to read the first one).
    What I'm finding is that a few of these Sounds don't play all the way through, but the SoundChannel dispatches the "soundComplete" event, and its final position matches the Sound's length.
    All sounds are converted from wav to mp3 at 44kHz / 16 kbps using dbPowerAmp. I faked out the compiler to avoid a reference to Flex by including a dummy SoundAsset that extends Sound.
    I don't know what other steps to take to debug this. Is there a way to figure out whether the problem is on the compile side or on the run side?
    More things I have tried:
    Looked at the Size report: The nonworking sounds were smaller in their embedded form than the source mp3
    Got rid of my own BitmapAsset and let Flash link in the Flex Framework and do whatever that does (definitely worse)
    Dropped the encoding from 44 kHz to 22 kHz (no improvement or worse)
    Dropped the bit rate to 8kbps (the lowest dbPowerAmp, the tool I use, supports). This usually helps somewhat, but I still usually use a word or two from the end of the file
    Dropped both parameters in the encoding. This helped a few that just dropping the bit rate didn't, but not all files. Plus it sounds tinny.
    Note that the file size and length of the Flash file does not seem to be what causes this--I have had 50k+ files that did fine, yet had a problem with files < 20k.
    Thanks!

    Have you tried disabling Omnisphere, just for a test, to see if the problem is occurring with just the built-in plug-ins?  Another thing to try, if you haven't already done so go ahead and display the CPU meter.. you to this in the app's Display preference pane. Then double click on the CPU side of the meter in the toolbar. This will open a CPU monitoring window... and you can instantly see how much CPU each plug-in is using... assuming it's a CPU overload that's causing it.
    Not sure if this is how you are using it, but if for instance you play something with Patch A and when you switch to Patch B you're either holding sustain or you want the sound to crossover into Patch B so it tails nicely... at this point you have both Patch A and Patch B active at the same time. If both those patches have 2 Omnispheres you actually talking about 4. Maybe this isn't exactly what you're doing, but you get the idea.
    Can you stand to have a slightly bugger size?  Maybe try 256. Oh, and definately quit all other apps and perhaps turn off airport.

  • Embedded sounds in my PDF are not playing on my iPad 3?

    I have installed a PDF on my iPad 3, I can view the document but all embedded sounds bytes do not work.  Is this a shortcoming of the Adobe Acrobat Reader 10.3 for iOS?

    Adobe Reader on mobile devices is not as advanced as Reader for Windows or Macintosh. It doesn't support multimedia (video or sound).
    I haven't found a free reader that does. You'll have to pay for a PDF reader. I suggest PDF Expert ($US9.99).

  • Playing embedded sound in a windows office doc on a mac

    Does anyone know if it is possible to play embedded sounds created in word docs on a windows machine on the Mac. Office for Mac does not work. The file seems to be looking for the windows recorder. Does anyone have any ideas for a workaround?
    Thanks in advance for any help.
    Dave

    No response to this So I am marking it answered just to clean up a bit

  • Javascript doesn't play() embedded sound

    This is a question about the PDF specification regarding how to use the javascript API
    to play a sound object.
    Specifically, why in my basic example is the javascript able to see the sound,
    but can't play() it?
    I have a test PDF illustrating my problem at
    http://www.affexion.net/test/PDF/test-scriptsound.pdf
    This is a stripped down example.
    The sound is referenced from a simple annotation
    on the left. Double-clicking it plays the sound as expected.
    On the right is a button which when activated is supposed to
    execute a javascript.
    << /S /JavaScript /JS ( console.show(); try {this.sounds[0].play(); } catch(e) { console.println(e.toString()); } console.println(this.sounds[0].name); ) >>
    I see the console open up, and I see it print the name of the sound "mySound",
    but I don't get the sound played.
    Do I need to do something in my javascript before I call this.sounds[0].play?
    Is there some other mistake in the way I have the sound object embedded and referenced?
    Thanks very much for any help.

    In followup, I have been able to accomplish what I wanted:
    use an embedded javascript to play an embedded sound
    For future readers, my example is (temporarily) at:
    http://www.affexion.net/test/PDF/sound-by-script.pddf
    How I did it:
    interaction of 2 components, the script and the (named) sound
    The script object looks like:
    << /S /JavaScript
    /JS ( console.show\(\); var s=this.getSound\("mySound"\); s.play\(\); )
    >>
    The named sound "mySound"
    The catalog needs an entry pointing to a name dictionary, like:
    1 0 obj << /Type /Catalog /Names XX 0 R >> endobj
    The name dictionary has an entry /Sound like
    XX 0 obj << /Sound XY 0 R >> endobj
    Then the actual name mapping:
    XY 0 obj << /Names [ (0xFEFFmySound) XZ 0 R ] >> endobj
    With the sound object at:
    XZ 0 obj << /Type /Sound /Length NNNNN >> stream...endstream endobj
    Key point: the string object (0xFEFFmySound) needs to be unicode-16 encoded
    with the first 2 bytes being FEFF.
    That was a real pitfall for me.
    Now that whole setup actually works.
    Sadly, though - I looked all through the PDF specification and
    in section 7.7.4 Name Dictionary, I don't see any Sound key.
    If anyone could explain how that sequence of Name dictionary to
    sound name is described in the specification, I'd appreciate it.

  • Embedding fonts as SWF

    Hi all,
    I am working on a mobile actionsxcript project and am having trouble embedding some fonts. The fonts are embedded in SWF files as only a small subset is needed and I am trying to embed the SWF files in my AS build and then access the fonts via their linkage names.
    I am not having any luck but am not really sure of the exact approach here so if anyone can shed any light or provide a tutorial/example that would be great as I am about to start banging my head on stuff.
    I am embedding the font swf like this:
    [Embed(source="assets/newfonts/FontFile.swf", symbol="fontInstanceName")]
    public var FontBold:Class;
    I assume I need to construct an instance and cast it before I can use the font (maybe wrong about this) but am unsure of the details.
    Thanks in advance for any help.

    Turns out to be really (embarressingly) simple and I'm not sure how it took me so long to get working.
    Add a new font to the library in Flash.
    Give it a linkage name and set it to export for actionscript.
    Publish the SWF
    Embed the swf in the actionscript project using [Embed(source="assets/newfonts/FontLib.swf", symbol="TestFontBold")]public var TestFontBold:Class;
    Set the 'symbol' parameter in the embed tag to be the flash linkage name of the font.
    Create a TextFormat object
    Create a Font object - var newFont:Font = new TestFontBold();
    Set myTextFormat.font = TestFontBold.fontName;
    Apply the TextFormat as usual.
    No idea how I had so much trouble with this when it is so obvious and straighforward. Oh well, that's often the case (with me at least)
    Cheers

  • Embedding Sound : The Sound File Control

    Newb here. Please bear with me.
    I am embedding sound files into an e-book, floating controls every 15 minutes reading time. The use may read and listen and the same time.
    It looks like I do not have much to chose concerning the sound player controls: the start/stop, beginning/end, and the position slider are really small, there are gray bars above and below, and everithing is sorrounded by a thick black border even though I select "no border" in the appearence option.
    Please advise. Thank you very much.

    You might try posting the the Acrobat ebooks forum: http://forums.adobe.com/community/acrobat/acrobat_ebooks

  • No sound in swf file

    I need to resize an flv file. I opened it in Flash and embedded it as a movie clip in the timeline. I also embedded into the timeline frame sequence. I was able to resize the file successfully. When I preview publish it as a swf file, it plays with sound in Flash. When I export the clip to a flv file, it doesn't play with sound. I have also tried to convert the flash from swf back to flv using After Effects, but there is no sound either in AE and when I play the converted file in Adobe Media Player. I am stumped on how to get any sounds from this file and appreciate any help I could get.

    Have you asked Maps Marker Pro for support for their product?
    https://www.mapsmarker.com/support/
    Chances are you need specific code for Gecko based browsers, which might need different code than Trident, WebKit, and Blink based browsers use.

  • Sound in SWF not working in PDF

    Hi all, I did a childrens book some time ago and I just reopened it in CS 5, applied the page turn animation to it and output it as SWF. It worked fine as an embedded SFW in the pdf - no problems.
    I then decided to add sound to each page and set the behaviour for the sound to start and stop as the pages are turned.
    This was all good when I tested the SWF outside Acrobat. I open the page - the sound plays
    I then added the swf output with the sound from InDesign to a PDF file. Everything works fine except - no sound.  Is there a way to embed the audio files in the SWF? I think this is probably the problem but I'm open to other suggestions.
    Best, Steve

    Any thoughts??
    Steve

  • Stop embedded sound playing before clip starts

    Hi,
    When I test my app on a device the sound starts playing before the movieclip.  The sound is embedded in an external swf.  I can access the sound using:
    SoundMixer.soundTransform = new SoundTransform(0);
    But I can't work out where to turn it back to 1 so it starts when the movie starts.  The code I'm currently using is below, but the sound still starts before the clip does.
    Thanks.
    private function startMovieOne(event:MouseEvent):void
                var defaultSWF:URLRequest = new URLRequest("movieOne.swf");
                loader.load(defaultSWF);
                loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, showProgress);
                loader.contentLoaderInfo.addEventListener(Event.INIT, onInit);
                loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
            private function onInit(evt:Event):void
                loader.contentLoaderInfo.removeEventListener(Event.INIT, onInit);
                SoundMixer.soundTransform = new SoundTransform(0);       
            private function showProgress(evt:ProgressEvent):void
                loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, showProgress);
                var loadProgress_percent:Number = Math.floor((evt.bytesLoaded * 100) / (evt.bytesTotal));
                trace("loadProgress_percent: " + loadProgress_percent);
            private function onComplete(evt:Event):void
                movieTwo_mc.addChild(loader);
                trace("loaded");
                loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onComplete);
                SoundMixer.soundTransform = new SoundTransform(1);

    i assume the sound is attached to a movieclip timeline (otherwise, use the sound reference).  movieclip's have a soundTransform property that you can use to control their sound.  you should be using that instead of the global SoundMixer soundTransform unless you have more than 1 sound and you want to control them all concurrently.
    and, you use the soundTransform like this:
    var st:SoundTransform=your_mc.soundTransform;  // though, you could continue to use the less desireable, var st:SoundTransform=SoundMixer.soundTransfom;
    st.volume=1;
    your_mc.soundTransform=st;  // again, if you continued using the global SoundMixer soundtransform, this would be:  SoundMixer.soundTransform=st;

Maybe you are looking for