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

I rarely use the sounds in AS3/Flash. I use Flash Pro CS6, but I can't seem to understand how access control (play, stop, etc) sounds embedded in a SWF external loading in the main SWF file.

It is easy to control them when they are incorporated on the main swf. However, on a responsible external SWR, I get all sorts of errors. For this application, I really need to incorporate in the external SWF file.

I've read several solutions, but none seems not to work.

I integrate the sound file mp3 called soundSegment1.mp3 tool to import Flash CS6 and then open the properties panel actionscript Flash select the name of the class: SoundSegment1. Can I change the class ID and create a file named SoundSegment1.as, and it saved right next to my document class main.as in the same directory. The code for 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 made 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.

Otherwise, 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'm stuck and I really need this to work. I would really appreciate your help.

Thanks in advance for any help provided. I really need to make it work, because I can not simply incorporate into the main SWF or load them individually outside one by one.

Thanks again!


You can use the load and loadCompleteF below:

var SWFToLoad: String =...;

var s:String = "SoundSegment1";

Load (SWFToLoad, s);

function load (urlS:String, classS:String) {}

var ldr:Loader = new Loader();

ldr.contentLoaderInfo.addEventListener (Event.COMPLETE, function(e:Event){loadCompleteF(e,classS);});)

LDR. Load (new URLRequest (URL));

}

function loadCompleteF(e:Event,classS:String):void {}

var loadedAppDomain:ApplicationDomain = e.target.content.loaderInfo.applicationDomain;

var C: Class = loadedAppDomain.getDefinition (classS) in class;

var instance: * = new C();

Sound (instance). Play();

}

Tags: Adobe Animate

Similar Questions

  • How to access and control my firewall

    I have Windows XP, SP3 with all updates installed on my computer.

    I have problems with a Web site - my browser find the URL and load the website, but the program never ask for my login details; and after a few seconds, the program displays the error message from the server from their site indicating the invalid client-server dialogue

    The web manager tells me to check MY settings, but not those who - I suspect that my firewall is causing the problem - how to manage the settings on MY firewall

    Hi Bob,

    1. have you done any hardware changes or software on your computer before this problem?

    2. what browser do you use?

    3. which site are you trying to access?

    If you use Internet Explorer, you can follow this link & check if the problem persists:

    You cannot view a secure in Internet Explorer 8 Web site

    Reference: You cannot connect to or connect to Web sites secured in Internet Explorer

    Hope the helps of information.

  • How to access and recover photos and data from icloud?

    How to access and recover photos and data from icloud?

    Sign up for settings/iCloud and turn on the various switches in sync. On a computer, go to system/iCloud Preferences, log in and check the different items to synchronize.

  • my computer is locked in the options admistritive and I for got my password. How to access and fine the password or change it?

    my computer is locked in the options admistritive and I for got my password. How to access and fine the password or change it?

    Hello dianeweeks,

    Thanks for the reply.  I have included a link below that I hope will help.

    Microsoft's strategy concerning lost or forgotten passwords

    http://support.Microsoft.com/kb/189126

  • I want to access and control my other laptop with wifi.

    * Original title: remote access

    I don't know anything then please help me from 0. I want to access and control my other laptop with wifi. I don't know where to start? Please?  Reference Dell w7 while the other is toshiba w8.

    (Moved from devices and drivers)

    You can do this with Remote Desktop.

    These can be useful:

    Remote Desktop connection: frequently asked questions

    The application of remote desktop help

    Remote Desktop in Windows 8

    John

  • Disable defender and Security Essentials due to conflicts, has blocked access and control other programs.

    Hello, I use Windows 7 on a HP G60 laptop. I disabled Windows Defender and Microsoft Security Essentials because I started running free Panda and Malwarebytes Antimalware version. Now an error window Defender blocking access and control of a large number of programs, the window message trying to force me to turn Defender. Disabling Security Essentials is causing other things to not work. I can not yet re - turn on Defender, if I try clicking on the link in the error window, it will not restart, expires.  Tried to turn it back on using the Task Manager, but there is no response at all if I click Start. Access to Services and programs in the start Panel are all both blocked by Defender error window.  I actually want defender and Security Essentials, because they are redundant and are in conflict with other programs I am running, but apparently they cannot be disabled without blocking access to my computer. I thought it was harmful to run all these programs of security in conflict between them, now I can't use my computer at all. Thanks for any advice you can give me.

    Thanks much for the advice. I have a few other questions. Defender is not separated from the essential? Then uninstall Security Essentials would have no effect on the Defender isn't it? My problem is that Defender deactivation now blocks access to many other programs with a Defender error window.  I read that Essentials was supposed to replace defender and Defender should have been stopped or disabled when Essentials has been installed. Is this correct? I didn't, got them both running.  When I installed Panda, I got a notification from Windows on the conflict and choose which program to use. Although I chose my own safety programs at the time, which was never disabled Defender or kept from running. So I finally did it manually by accessing the properties in Services to change the startup type to disable, which is when all the trouble started.

  • How to access and replace a pavilion dv7-3173nr cooling fan?

    Pavilion dv7-3173nr member of my family had a cooling fan stop working. This has been noticed during my usual maintenance of it where I take a can of compressed air and spray to clean the fan. As he hit the air I was expecting the fan to turn but it did not. I've then turn it on to see if it would turn but it would turn still not. The warranty just missed in recent weeks and the manuals and other resources that I've found so far do not help. If someone could tell me how to access the fan for this model, it would be appreciated.

    Thanks in advance

    Spudnut

    Hello:

    Here is the guide of maintenance and maintenance for the laptop dv7 series:

    http://bizsupport2.Austin.HP.com/BC/docs/support/SupportManual/c01918142/c01918142.PDF

    Component R & R procedures can be found in Chapter 4. See page 99 for details on how to remove the fan.

    Reference numbers are also provided to chapters 3 and 4.

    Paul

  • How to install and boot Windows xp on an external hard drive (USB)?

    Can you please help on above question?

    UBCD (Universal Boot CD) might be a good candidate.  It creates an ISO file with a fully functional version of XP that you can burn to a CD, and then copy them to an external drive.  You can download http://www.download.com .  Be aware that you will need a XP SP1 or disc to create the ISO installation file later.

    Good luck.

  • Unload and kill the noise of an external SWF

    I have the following program to read a movie .flv on a webpage made by myself:

    var Xpos:Number = 0;

    var Ypos:Number = 0;

    var swf:MovieClip;

    var loader: Loader = new Loader();


    var mySWF: URLRequest = new URLRequest ("http://.../.swf");

    Loader.Load (mySWF);

    Loader.x = XPos;

    Loader.y = YPos;

    addChild (loader);


    loader_btn.addEventListener (MouseEvent.CLICK, loaderClick);


    function loader_btnClick(event:MouseEvent):void {}

    removeChild (loader);

    var newSWFrequest:URLRequest = new URLRequest ("http://.../.swf");

    loader.load (newSWFrequest);

    loader.x = Xpos;

    loader.y = Ypos;

    addChild (loader);

    }


    close_btn.addEventListener (MouseEvent.CLICK, close_btnClick);

    function close_btnClick(event:MouseEvent):void {}

    SoundMixer.stopAll ();

    loader.unload ();

    bg_movie_mc. Visible = false;

    close_movie_btn.visible = false;

    bg_movie_mc.stop ();

    }

    When I post the preview, it works well and I can unload and kill its sound by clicking on the close button. When I publish the page to the site and load the movie via a "loader_btn", it works well and when I click on the close button, the image disappears , but the sound is maintained. Who has an idea for her? Thanks in advance!

    you are editing for fp 10 or above?  If so, use:

    var Xpos:Number = 0;

    var Ypos:Number = 0;

    var swf:MovieClip;

    var loader: Loader = new Loader();

    var mySWF: URLRequest = new URLRequest ("http://.../.swf");

    Loader.Load (mySWF);

    Loader.x = XPos;

    Loader.y = YPos;

    addChild (loader);

    loader_btn.addEventListener (MouseEvent.CLICK, loaderClick);

    function loader_btnClick(event:MouseEvent):void {}

    removeChild (loader);

    var newSWFrequest:URLRequest = new URLRequest ("http://.../.swf");

    Loader.Load (newSWFrequest);

    Loader.x = XPos;

    Loader.y = YPos;

    addChild (loader);

    }

    close_btn.addEventListener (MouseEvent.CLICK, close_btnClick);

    function close_btnClick(event:MouseEvent):void {}

    loader.unloadAndStop ();

    bg_movie_mc. Visible = false;

    close_movie_btn. Visible = false;

    bg_movie_mc. Stop();

    }

  • Action Script 3 Code to play and stop a file Fla or external Swf using game, stop button, in, the FLA file

    Thank you for all the answers before.

    I need a code Action Script 3 humbly for playing and stopping at a file Fla or Swf external button Play or Stop in Parent Fla or Swf file.

    I should have the opportunity to revisit the Fla of Parent file of the external file using the key.

    For example: I 'Introduction' Fla that has a button to play an external Fla called "set up."

    And in the 'set up' ALF, there is a button to play 'Introduction' in Florida.

    Kind regards

    God bless you

    the eaiest way is to use the content property of your charger (cast as sprite or movieclip) to reference the main storyline in the loaded swf file, and to use parent.parent to the timeliine of reference containing your charger (assuming that it has been added) go up again as the appropriate object.

  • On some documents, I get an error message that ends with "...» create an association in the Set Associations control panel. "Why do I get this and how to access this control panel?

    Need help to access the Panel Associations value so I can open the docs have no association, according to the error message that I receive

    Ideas:

    • You have problems with programs
    • Error messages
    • Recent changes to your computer
    • What you have already tried to solve the problem

    You need a program on your system to open these documents (file types), and the program must be associated with the file type. Go to start / Default programs / associate a file or Protocol with a program and scroll down to the types of files of these documents.  Can the default program open this type of file or the file type is same?  If this isn't the case, you will need to install a software that can read and open possibly work with the types of files in question.  Exactly which types of files you can not read (what are their extensions - the three digit after the name of the file identifier). ?  If you do not see the extension, go to start / Control Panel / folder Options / View / and uncheck Hide extensions of known and then file types try to look at the files again.

    Please post back with results or if you have other issues (as may have answered your question).

    I hope this helps.

    Good luck!

    Lorien - MCSA/MCSE/network + / has + - if this post solves your problem, please click the 'Mark as answer' or 'Useful' button at the top of this message. Marking a post as answer, or relatively useful, you help others find the answer more quickly.

  • How to access a control known in one reference VI?

    Hello.

    I want to open a Subvi, which is one of the many slot - VI with the same input and output.  But I can't seem to find a way to go directly to one of the terminals.  I think I found a part of the solution in this thread (http://forums.ni.com/t5/LabVIEW/How-can-i-get-the-reference-to-Controls-from-VI-reference/m-p/510319...), but I'm kind of stuck right before the finish line, I think. -Can someone help me with this?

    Below you can see what I have so far.  The path will be changed runtime based on the config files, but controls entry and exit in VI will always be the same.  As you can see, I tried wiring in the type of the VI to the open reference VI block.  I've also attached the sub - VI which indicates what controls and indicators that are used.

    Specifically, I want to be able to enter a number for the control of the input buffer and to be able to read all the flags in the cluster of Test data (preferably using for example. Ungroup by name).

    Thanks a bunch for all help!

    If all the SubVIs have the same connector component, you can use the call made by the reference node.

  • unmute and control the sound level

    How can I manage Mute on and off control?

    R.Click the speaker of the clock, select playback devices, locate materials, properties, change... In addition, most

    keyboards have this function.

  • How to use and control the tabs?

    Sorry for such a general question, but I use Firefox with older versions of Mac OS x for years and have just been struck by this brand new and I have no idea on your tabs, "new tab page" etc. Can you just send me some documents so I can understand what they are and how to use them?

    All I see on my headers Ff are all sorts of legs that have no relevance to me, like 'how to stop Firefox from... '. "(twice), a few other symbols Ff and other"tabs"I don't know everything." All the do is filling up a bar line.

    Thank you-

    You are welcome.

    If you have any other questions feel free to ask them.

  • How can I dynamically control the sound

    Hello
    In the header part of my site, I have included a flash with sound, it plays automatically when the page is loaded, if I stop the sound in homepage, it plays the sound, when I go to another page. I want to play the sound continuously, even if the pages are loaded. How can I solve this problem?

    The problem is that the whole page reloads when you click on a button.
    My suggestion would be to frameset to load separate pages in a separate frame navigation. This should keep the music played on all pages as navigation charges ever.
    Also, I noticed that there is no way to start playing the sound again after you stop it once.

Maybe you are looking for

  • No signal to monitor

    I received my new H50-50 the other day, but could not check that my monitor has a DVi connector that the computer has a VGA connector. I sent for an adapter so I can use the monitor which I just got. On the connection it upward and turn on the comput

  • Cannot detect the instrument (TDS 210)

    Hello, I have difficulty to connect PC tektronix TDS 210. I use GPIB USB HS, operating system is windows 7, NOR-488-3. The problem is after I installed everything needed for this configuration, using the measurement and automation, I can't detect Tek

  • HP - Pavilion x 360: black screen

    My laptop turns on request for password goes through the process making known but then goes black, but I can see the mouse cursor and can move even the pop-up to renew my virus software rises and the Task Manager works but except that it stays black

  • delete contacts in windows live mail.

    When am I going to send my wife some thing to work, I type the first letter of (c) address and I get several suggestions. only is good. My question is how to remove those who is not correct? Thanks in advance for any help. Jim

  • Place of Dell pro 11 General check.

    So I just try to assess how much is my used Dell 11 pro and there are a few things that I'm not sure if they are bugs our real problems, I need to worry then here it goes: My meeting place is the 7130 i5 4 GB 128 ssd type. And I have already noticed