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.

Similar Messages

  • How to access and control a Windows 7 computer from a Mac - long distance?

    I bought my parents their very first computer. They are 2000 miles away in another state. Currently I have the computer in my possession to "set-up" everything so it is as seamless as possible when they receive it.
    It is an HP with Windows 7. I have a mac. I would like to remotely access their Windows machine to help them when they need it - to be able to control theirs to show them how to do things and to do it for them if need be.
    Thank you for your time
    Pattie
    This is a new thread. If you want to see the original info it is at this link:
    http://discussions.apple.com/message.jspa?messageID=12832917#12832917

    You are only as secure as web browsing to the LogMeIn website is (which appears to use HTTPS). If your login on that site is compromised, they will have a list of your computers that they can attempt to connect to. As long as you don't save the login credentials, they would then also need to know what username and password to use to connect to the computer. Granted, a little social engineering, and they could probably get some good ideas what to try for those, but if you chose to make your computers secure with complex and hard to guess passwords then it should be fine.
    I've been using LogMeIn from my Mac to my mom's Windows XP system from July 2009, and to my wife's Thinkpad running Win 7 since Oct 2009. None of the computers involved have had any security issues at all, let alone any caused by LogMeIn. For my wife's PC, it sits behind our NAT Firewall in our LinkSys Router (although I did have it behind a CheckPoint VPN Edge router for a while). My Mom's PC sits behind a Netgear Router providing its NAT Firewall. When my Mac isn't at home, it's generally behind that CheckPoint VPN router at my office now. It all works nicely from behind one router to behind another. The Piece that you install on the PC will log it into the LogMeIN website and that is how it gets through the router to the PC. You login to the website, select the PC to control, then login to that PC.

  • I need to know how to access and use the Blue Tooth device that comes with the Thinkpad W520

    Forgive me for being a techo illiterate. But I know that this thing supports Blue Tooth. And one "problem" with it is although it has a DVD and sound card, music and movies have very lousy audibility. Is there something I can do about that? I can barely hear anything on a movie unless I plug in head phones to the computer. But that leaves me stuck in my seat. I'd like to get cordless headsets. And I'm ready to purchase the Plantronics BackBeat 903+ Wireless Stereo Headphones - Mic, Rich Audio, Bass-boost, Voice Alerts, OpenMic, 3-way Earpiece. And have heard that it's compatable with a pc that has Bluetooth capabilities. but could someone get back to me with exactly how I access and use the Blue Tooth device?

    I was searching for how to setup the 903+ and my W520 and came to this thread.
    1. The OP was asking about audio and there are updated audio drivers / tweaks to get it louder / install different drivers.
    but if you are going to go BT headset....
    2.  What I did for the 903+
    Uninstalled the currently installed ThinkPad Bluetooth program. ( I forget the exact name, came stock and was out of date).
    Required reboot.
    Activated the Bluetooth with FN + F5 menu.
    Downloaded the updated Bluetooth driver from lenovo (search lenovo driver matrix).
    Ran the updated Bluetooth driver install.
    Rebooted for good measure.
    Double-clicked the Bluetooth Tray icon.
    Clicked Add A Device.
    Turned off my 903+ and continued to hold down the power to enable pairing mode.
    Showed up in devices and added it.
    Worked for audio. There are probably additional options for enabling the mic.
    Hope that helps whoever might find this thread.

  • How to access the control menu

    How to access the control menu(Restore,move,minimize,maximize,close) of JFrame and JInternalFrame can be accessed using Keyboard like in windows(Using space bar for any window we can access the control menu of that window in Windows OS).
    How to achieve this feature in Java for JFrame and JInternalFrame
    Any sample code will be helpful

    try search the forum with topic: control menu on-off

  • Logical database PSJ:   How to access and link tables inside that???

    Hi,
    I have a requirement like :
    I have to write one report which will display project statuses (PSmodule) using the LDB PSJ.. I am using LDB because I neeed dynamic selection screen.
    I need to acees the data from table like 1. PROJ, prps_r and JCDS under the LDB PSJ.. but when I found the hirarchy of these table in the LDB , then all 3 tables are at same level.
    then How to access and link data from theses 3 tables using GET and LATE command.
    I did like below, but wrong number of records are coming
    START-OF-SELECTION.
    GET proj.
    GET prps_r.
    GET  elm_ps .
    GET jcds.
    can anyone tell me, what 's wrong here.
    points will be rewarded
    for proper answer.
    Regards,
    Mrunal

    hi ...get is like a loop in ldb. then if you use the 3 get statements then it will loop with in a loop with different data..

  • HT2534 How to access and install appstore free apps without providing credit card number because I do not have one?

    How to access and install appstore free apps without providing credit card number because I do not have one?

    Creating an iTunes Store, App Store, iBookstore, and Mac App Store account without a credit card
    Step 3 is important, no matter whether you do this on a Mac or an iPad / iPhone:
    Important: Before proceeding to the next step, you must download and install a free application. ...
    Important: Before proceeding to the next step, you must download and install the free application by tapping Free followed by tapping Install App. ...
    To summarize, you must first download a free app from the App Store. When you are asked to sign in with your Apple ID, select "Create new account". Accept the terms and conditions checkbox, then click Continue. After you enter all the requested personal data, click Continue.
    When you are asked to select a payment method, select "None". 
    That's all there is to it.

  • How to run and control any program by java

    hi everyone ,
    I wonder that how to execute and control some menus or how to use some property of any program by java, not for the whole program, it's just only a few features of program.
    Is there any idea?
    if it's impossible to do with java , how can I do it? which way?
    thanks a lot..

    No. Applications have to be specifically built to be able to be controlled by other programs; for example office applications allow you to communicate with them through a special protocol. To be able to communicate you need to know the protocol and write specific code for specific tasks.
    The software world is not as simple as they show in movies, where hackers just press two buttons and take control over entire buildings and applications.

  • How to access another control in a page in another xaml file?

    I have a XAML page name GameMainSP.xaml. Can I access a control in that page from a module in the project? I was only trying to change a text block controls Text property. Is this possible?
    Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering
    - Yoda. Blog - http://www.computerprofessions.co.nr

    I have a XAML page name GameMainSP.xaml. Can I access a control in that page from a module in the project? I was only trying to change a text block controls Text property. Is this possible?
    Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering
    - Yoda. Blog - http://www.computerprofessions.co.nr
    Nevermind, I managed to figure out what was the problem. I needed to provide a reference to the page.
    Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering
    - Yoda. Blog - http://www.computerprofessions.co.nr

  • How to start and control a WIN console application out of Labview ?

    I have a windows console application, which requires user inputs (keystrokes) during the application run. Now I want to start and control this application out of labview (8.5). Has anyone a good idea, how this can be done ? The "System Exec.vi" seems to be unsuitable, because you can not pass any data to stdin during the run of the application.

    Well, of course I agree absolutely with JoeLabView that Cheap + Fast != (not equal) Good. My company is a manufacturer for medical devices. These are long-living (compared to consumer electronics) and therefore it is extremly important for us that my written code is manageable, reusable and stable. Thats the reason, why I spent  time to think about the really best solution for my task here and I am very amused that we can share our knowledge here in this forum.
    I also thinked about creating a DLL as suggested by smercurio. If I will solve my task in that way, I still have to remove the User Interactions and call the appropriate subfunctions directly. If a newer ART-Tool will be used in the future, this work must be repeated. It that maybe that the developer must go deeply into the coding of the tool. Nevertheless it is a possible way, of course.
    Actually I thinked about a further solution I want to discuss with you. The .NET framework provides functions for redirection of standart input and output. Refer to the explanation of  "ProcessStartInfo.RedirectStandardOutput Property" and "ProcessStartInfoRedirectStandardInput Property" within the .NET Framework Documentation, there are also some examples of how to use them. With this background knowledge, I think that it must be possible to write some kind of wrapper code, which starts the tool and redirects the input/output to labview. The code maybe implemented as a DLL which can then being embedded into LV, or as a separate executable file, whereby the communication between LV and the wrapper code may be done over TCP for example. What do you think about this attempt ?
    @smercurio:
    >> trying to use the ART-tool as it is for automated testing will cause you grief in the long run ....
    Where exactly, did you have the problems? Did you have the problems across multiple art revisions ? What was your "main" problem ? Please let me know your experience, cause I do not want to run into similar problems.

  • How to access and display a Web Service from a WSDL in JSP or JSTL ?

    Dear All,
    We need to access a Web Service which is hosted as WSDL How to access a WSDL file from JSP or JSTL, parse and display the SOAP response in JSP page.
    Any simple example or URL as reference to an example will be useful for me.
    It seems io tags of jakarta is able to send soap message, but how to display it in JSP.
    Yours,
    Sankar.B

    Dear Sir,
    Yes. I would like to know more about the Forte and how to consume WSDL file from JSTL. The following are my querirs.
    1. How to connect the declared JNDI from a JSP page. i.e: the Datasource - ex: booksDS
    2. We connect the Tomcat server using JNDI as jdbc/scott. But, if I give jdbc/scott in JSTL as datasource={jdbc/scott}, we could not able to connect. We use the following code in a JSP page to connect the DB from a JSP page. (Its quite easy to modify, so we use the connection in a JSP page.)
    3. How to Consume a WSDL url from JSTL. Ex: If there is a URL : http://localhost/ws/MathService.asmx?wsdl OR http://www.xmethods.com/test/BabelFish
    4. How to display the result. We tried via SOAP from io taglib of Jakarta, but gives us an SOAP (it also looks like xml) response. But, how to use the value from that soap response in IE client thru JSTL/JSP.
    5. Whether this JSTL tool will be available with Forte Enterprise/Community Edition. If so EE, whats the price.
    Please Reply Immediatly. We tried, trying, going to try to display a wsdl response, but not able to display in IE thru JSP/JSTL. But, weve tested the www.gotdotnet.com examples of asp.net web services, we are thru. Its quite easy it seems in .NET. But, we feel whether even there is not even one example in JSTL/ Java Web Services Dev. Pack to utilise a web service in full cycle. The example which uve given is thru servlets. We dont use servlets. Cos, its very easy to edit JSP pages, instead of compiling the serv. and using it.
    I hope ull reply for all the above queries, since ur from SUN.
    Expecting your fav. reply.
    Yours,
    Sankar.B

  • How to access and restore the files in recovery D on my HP Pavilion Windows 7??????

    Im not very good with the technological side of computers, but it asked me to restore to factory settings after turning my computer on in the morning. I asked it to back up my computer so I can restore it which I believe it did to the Recovery D drive. I can open this file but it comes up with
    Recovery Partition Warning
    This area of your hard drive (or partition) contains files used to perform and system recover.
    Do no delete or alter any of these files
    Any change to this partition could prevent a system recovery in the future.
    It also says there is 1.94GB free of 15.7GB which must mean there are files in there but I dont know how to access them.
    Please help and please try to speak in term in which I may understand. As I said I dont really understand computer language lol.
    Thanks in advance for your help.

    Thank you. I think I completely stuffed it up. I didnt put anything into my computer to back it up like an external hard drive because I dont think I actually know what the computer was doing at the time so looks like I may have lost all my previously applications, settings and data. Oh well I'll have to live with that, Thanks for your help much appreciated

  • How to access and run places maintenance add on?

    10/4/2014 Thank you Cor-el for your rapid response to my original question. I do believe I downloaded the Places Maintenance add on. But I have no idea as to how to access that add on and run it, if that's what I should do. I did try to restore a backed up HTML bookmark file. This seems to have changed the "wrong" URL that I get to a different wrong URL. Thanks.

    Hi Royma
    We prefer to keep the discussion in one thread, so I will lock this thread.
    Please continue here:
    *[[/questions/1023735]]

  • How to run and control live cams on applets

    hi
    i want to now how can we run and control live images form a camera on to a aaplet.what technologyi used for this project . u can check the url http://www.jal.co.jp/en/live/ as a demo.plz can anyone guide me.how to start and which technologies to use,
    regards
    sheetal

    start with this:
    http://search.java.sun.com/search/java/index.jsp?col=javaforums&qp=&qt=%2Blive+%2Bcamera&x=11&y=12

  • How to view and control a VI remotely from a web browser

    Hello,
    I want to see and control a vi using a web browser.
    I followed the steps recommended in help and I can see and control the front panel of my vi.
    So far everything is OK.
    First problem:
    A button activates a simple window display a message (One Dialog button). The dialog box opens on the server computer but can not be seen in brouser and therefore can not be closed remotely.
    The second problem:
    Another button activates another window (vi) loaded dynamically. The VI is reentrant and is open with option 0xC0 ("Enable simultaneous calls on reentrant VIs" and "Prepare to call and forget"). By activating the button, it opens multiple instances of the VI properly and runs on the server computer, but their are not visible to the client computer.
    I created, after the same algorithm, corresponding HTML file for the dynamically loaded VI and it is saved in the same place with the main program HTML file.
    What to do as the client computer can operate main VI and adjacent windows from the browser?
    Thanks,
    Cristian
    Solved!
    Go to Solution.

    Another option would be to use something like WebSockets and have your LabVIEW application communicate with a web-page you've designed/developed with Javascript. Then you can use things like floating windows/dialogues with jQuery. It's a lot of work though as you'll need to define your websockets API for talking to your application and then develop the web-page in HTML/CSS/JavaScript for your user interface.
    Unfortunately, even browsers are moving away from pop-up windows (chrome and various addons tend to block popups and they don't play nice with mobile devices). You can have semi-dialogue-like pop-ups though with modal dialogues: https://jqueryui.com/dialog/#modal-message Note though that they are contained within the browser window.
    My advice would be to think about creating a custom UI in LabVIEW that works with a single pane / panel (you can use tab controls!) and use that with remote front panels. Then decide if you want to invest the time/effort in a WebSockets/Web Services approach with your own browser-based UI. Note as well that remote front panels don't work in Chrome properly any more.
    Certified LabVIEW Architect, Certified TestStand Developer
    NI Days (and A&DF): 2010, 2011, 2013, 2014
    NI Week: 2012, 2014
    Knowledgeable in all things Giant Tetris and WebSockets

  • Q: How to access and modify xml tags using Java

    I have an xml based document that i need to access and change. For example, the code
    <section id="section1">
    <div>
    <xforms:group id="id1">
    <xforms:label id="label1">
    <l style="font-size:16pt"> something </l>
    </xforms:label>
    </xforms:group>
    </div>
    </section>
    Working with Java I need to access all the tags, select some of them that are relevant to the current device and remade the document. I thought I would read the file character by character identifying the different labels and building a tree, storing in the tree nodes the relevant information as some kind of attributes (for example, in the case of the <xforms:group id="id1"> I would name the node "xforms:group" and create an "id" attribute with value "id1"). I'm not sure if that is the most efficient way of accessing the problem (computational power might be an issue), and would appreciate some help on the subject.
    Thanks,

    this may help you..
    this is a little util i made to help me read/write files.
    using this, you are only one step away from your solutions, you only need to figure out the regex you need to run on the text of the file to make it become what you need it to become.
    though if you use non-standard encoding, you might not want to use this code..
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.Arrays;
    public class ASCIIFile {
         private File file;
         private StringBuilder builder;
         public ASCIIFile(String path) throws IOException{
              file = new File(path);
              openFile();
         public ASCIIFile(File file) throws IOException{
              this.file = file;
              openFile();
         public void setNewFileName(String fileName){
              file = new File(file.getAbsolutePath(), fileName);
         public void setNewFilePath(String filePath){
              file = new File(filePath, file.getName());
         private void openFile() throws IOException{
              if(!file.exists()) file.createNewFile();
              BufferedReader read = new BufferedReader(new FileReader(file));
              String line = read.readLine();
              builder = new StringBuilder();
              while(line != null){
                   builder.append(line);
                   builder.append("\n");
                   line = read.readLine();
              read.close();
         public String getContents(){
              return builder.toString();
         public StringBuilder getStringBuilder(){
              return builder;
         public void setStringBuilder(StringBuilder b) throws IOException{
              setContents(b.toString());
         public void setContents(String contents) throws IOException{
              FileWriter writer = new FileWriter(file);
              writer.write(contents);
              writer.flush();
              writer.close();
              builder = new StringBuilder(contents);
         public static File[] getAllFilesUnderDir(String fullpath, boolean recursive) {
              ArrayList queue = new ArrayList(10);
              ArrayList matched = new ArrayList();
              File root = new File(fullpath);
              File[] files = root.listFiles();
              if (files == null || files.length == 0) {
                   return new File[] {};
              queue.addAll(Arrays.asList(files));
              for (int j = 0; j < queue.size(); j++) {
                   File child = (File) queue.get(j);
                   if (child.isDirectory() && recursive) {
                        files = child.listFiles();
                        if (files != null) {
                             queue.addAll(Arrays.asList(files));
                   } else { // child is file
                        matched.add(child);
              return (matched.size() > 0)?((File[]) matched.toArray(new File[] {})):(new File[] {});
    }

Maybe you are looking for

  • Video Tracking in Flash

    Does anyone know how to do video tracking in flash? I want a camera to record movements and transfer them in real time as commands to an object in Flash. Is this even possible?

  • Denim Update for Lumia 1520

    Why can't a flagship device like Lumia 1520 get the latest updates ? What's the point in purchasing the top of the line products if no support is provided. How can Microsoft retain its loyal customer with such a poor service? What is the point of adv

  • Is it possible to ignore error messages in BAPI_SALESORDER_CHANGE  ?

    Dear all, I encountered another problem today which I hope you can help me with. During manual Sales Order Change, customizing triggers an error message which can be ignored for the special case I'm dealing with. It will pop up, but - like a warning

  • Importieren von Fotos in Lightroom: Grundlegender Workflow

    This discussion has been automatically generated for: http://help.adobe.com/de_DE/lightroom/using/WS427A4C94-2499-456d-8E17-AE09D3316A03.html.

  • Nokia 5700 XpressMusic Browser Crash

    My Nokia 5700 XM's Web Browser crashes as soon as i run it. As soon as i click on "Browser", it seems like opening, but quits suddenly.. Please let me know how to restore it.. I'm very much in need of it.. And also some of the applications seem to re