Modular sound function

Hello

I'm a newbie in AS3.  I'm doing my quiz tutorial as modular as possible.  Is there a way to earn his modular.

For example, I have several instances of movieclip to right_mc (for answers)

I have this code on each image with the right_mc button:

var soundReq:URLRequest = new URLRequest ("rightanswer.mp3");
var sound: Sound = new Sound();
Sound.load() (soundReq);

sound.addEventListener (Event.COMPLETE, onrightComplete);

function onrightComplete(event:Event):void
{
Sound.play();
}

Is it possible to make the above modular code so that it is a reusable function?  In this way, that I wouldn't put on each image in the correct answer. I was thinking something like this (but it does not work):

good answer button sounds
var rightsoundReq:URLRequest = new URLRequest ("rightanswer.mp3");
var rightsound:Sound = new Sound();
RightSound.Load (rightsoundReq);

rightsound.addEventListener (Event.COMPLETE, playRightSound);
function playRightSound(event:Event):void
{
right_mc. Sound.play();
}

playRightSound (right1_mc);
playRightSound (right2_mc);
playRightSound (right3_mc);
playRightSound (right4_mc);
playRightSound (right5_mc);

I understand.  my suggestion is best.

in frame 1, place:

function playSound(mp3:String):void {}

var s:Sound = new Sound();

s.addEventListener (Event.COMPLETE, soundloadCompleteF);

s.Load (new URLRequest (mp3));

}

function soundloadCompleteF(e:Event) {}

Sound (e.currentTarget). Play();

}

in any image where you want to play appropriate sound, use:

playSound ("rightanswer.mp3");

in any image where you want to play a bad sound, use:

playSound ("sad_trombone.mp3");

Tags: Adobe Animate

Similar Questions

  • Problems with the sound function and scrolling on the touchpad on my Satellite A500/026

    Hello

    I just brought a new laptop A500/026 and when I play music from my ipod I get a little static pop sound at regular intervals during the song... this happens on all my music. I accidentally scroll horizontally through my touhpad and my screen minimizes or maximizes. I try to find how I did it, but can never seem to return to its normal state. There is obviously some sort of function here, can someone help me with it? I installed the x 64 bit version of windows 7.

    Thank you

    Eddie

    Hello

    The touchpad settings are placed in Control Panel-> mouse
    You can find the additional tab which would be you can access touchpad properties.

    As I know the touchpad properties contains many different options that allows you to configure the scrolling function, to activate and assign different actions to the touchpad corners, etc.

    Check it!

  • Impossible to activate the sound function

    My hp630 not allow its service after this how can I enable

    Hi Salihi,

    What exactly happens when you try to activate the audio service?

     

    Method 1:

    You can use the troubleshooter below.

    A convenience store is an automated tool that can find and automatically fix problems with your PC. Audio troubleshooting can diagnose and troubleshoot equipment and playback of sounds common.

    Method 2:

    Update the drivers for sound card on the Web site of the manufacturer and check if it works:
    Note: If you use the 32-bit operating system, download and install the 32-bit drivers. If you use the 64-bit operating system, download and install the 64-bit drivers.

    Reference:

    No sound in Windows

    http://Windows.Microsoft.com/en-us/Windows/no-sound-help#no-sound=Windows-8&V1H=win8tab4&V2H=win7tab1&V3H=winvistatab1&v4h=winxptab1

    Please post with the State of the question.

  • No sound on Vista as administrator system

    From what I've seen here, this problem has been going on for a few years now.

    I did everything under the Sun and have still no system sounds and sounds no online who use Adobe Flash Player. The only thing I have not seen someone mentions is the fact that if you go into another user account that is defined as a Standard user sounds function very well.  Under the administrative user the system sounds and the sounds online will not work.

    You can't test the system sounds in the sounds tab. You get no sounds. You can test your speakers in the Read tab and get the perfect sound.  You can also go to the Windows Media folder and test the system sounds from there and they work perfectly.

    I also ran the cmd and it also showed this:

    2011-08-11 19:48:17, 000001bf CSI Info [SR] verification complete
    2011-08-11 19:48:17, CSI Info 000001 c 0 [SR] repair of components 1
    2011-08-11 19:48:17, CSI Info 000001 c 1 [SR] beginning operation check and repair
    2011-08-11 19:48:17, CSI Info 000001 c 2 hashes of file members \SystemRoot\WinSxS\x86_microsoft-windows-p... rtmonitor-tcpmonini_31bf3856ad364e35_6.0.6001.18000_none_d278d2aaa749970e\tcpmon.ini is not actual file [l:20 {10}] "tcpmon.ini": "
    Found: {l:32 b:as3OOcx5px0XiJa7f7s9BVvlW/FFlKR4NMU/T + TOP/Kg =} expected: {l:32 b:ENtKeUct91LKlHclgfWTvnCdCOHHwDe + SYrPzZTTezU =}
    2011-08-11 19:48:17, CSI Info 000001 c 3 [SR] cannot repair the military record [l:20 {10}] "tcpmon.ini" Microsoft-Windows-printing-StandardPortMonitor-TCPMonINI, Version = 6.0.6001.18000, pA = PROCESSOR_ARCHITECTURE_INTEL (0), Culture neutral, VersionScope = 1 nonSxS, PublicKeyToken = {l:8 b:31bf3856ad364e35}, type neutral, TypeName neutral, neutral to the public key in the store, hash mismatch "
    2011-08-11 19:48:17, CSI Info 000001 c 4 hashes of file members \SystemRoot\WinSxS\x86_microsoft-windows-p... rtmonitor-tcpmonini_31bf3856ad364e35_6.0.6001.18000_none_d278d2aaa749970e\tcpmon.ini is not actual file [l:20 {10}] "tcpmon.ini": "
    Found: {l:32 b:as3OOcx5px0XiJa7f7s9BVvlW/FFlKR4NMU/T + TOP/Kg =} expected: {l:32 b:ENtKeUct91LKlHclgfWTvnCdCOHHwDe + SYrPzZTTezU =}
    2011-08-11 19:48:17, CSI Info 000001 c 5 [SR] cannot repair the military record [l:20 {10}] "tcpmon.ini" Microsoft-Windows-printing-StandardPortMonitor-TCPMonINI, Version = 6.0.6001.18000, pA = PROCESSOR_ARCHITECTURE_INTEL (0), Culture neutral, VersionScope = 1 nonSxS, PublicKeyToken = {l:8 b:31bf3856ad364e35}, type neutral, TypeName neutral, neutral to the public key in the store, hash mismatch "
    2011-08-11 19:48:17, CSI Info 000001 c 6 [SR] this element is referenced by [l:160 {80}] "' Package_30_for_KB936330 ~ 31bf3856ad364e35 ~ x 86 ~ ~ 6.0.1.18000.936330 - 187_neutral_GDR" "
    2011-08-11 19:48:17, CSI 000001 c 7 hashes for Member file Info? \C:\Windows\System32\tcpmon.ini are not real file [l:20 {10}] "tcpmon.ini": "
    Found: {l:32 b:as3OOcx5px0XiJa7f7s9BVvlW/FFlKR4NMU/T + TOP/Kg =} expected: {l:32 b:ENtKeUct91LKlHclgfWTvnCdCOHHwDe + SYrPzZTTezU =}
    2011-08-11 19:48:17, CSI Info 000001 c 8 hashes of file members \SystemRoot\WinSxS\x86_microsoft-windows-p... rtmonitor-tcpmonini_31bf3856ad364e35_6.0.6001.18000_none_d278d2aaa749970e\tcpmon.ini is not actual file [l:20 {10}] "tcpmon.ini": "
    Found: {l:32 b:as3OOcx5px0XiJa7f7s9BVvlW/FFlKR4NMU/T + TOP/Kg =} expected: {l:32 b:ENtKeUct91LKlHclgfWTvnCdCOHHwDe + SYrPzZTTezU =}
    2011-08-11 19:48:17, CSI Info 000001 c 9 [SR] could not reproject corrupted file [ml:520 {260}, l:46 {23}] '------? \C:\Windows\System32"\[l:20{10}]"TCPMon.ini '; source file in the store is also corrupted
    2011-08-11 19:48:17, 000001 ca CSI Info repair results created:

    I think by now someone at Micrsoft would have a solution to this problem.

    Here is how I have not solved my no system sounds or sounds online video:

    Beginning

    Type Regedit

    Right click on Regedit

    Run as administrator

    Edit

    Permissions

    Advanced button

    The Edit button

    Put a check mark in the box for full control

    Then OK or apply

    My sounds were back.

  • Keep playing sound after pressing the home key in iOS

    Hello!

    I have an application that loads an MP3 from a URL and then read it (Flash cs6 - Air 3.9)

    In Android (when I publish it as APK), when the user press Power, or reduce the App, the sound continues to play (I like)

    But the same code in iOS, when I press Home or Power, the sound "paused" and continue playing only after I re - activate my App.

    I tried to resolve it with this line of code:

    NativeApplication.nativeApplication.executeInBackground = true;

    But without success.

    Everyone please help me what should I do to prevent the INTERRUPTION of the sound in my application after pressing Home and Power iOS ?

    Thank you in advance.

    Hi Pouradam,

    I know it sucks.

    On iOS, the only way to have a sound be played while the application is reduced to a minimum, is if the application is actually running in the background (obviously).  To do this in the application manifest, you must set UIBackgroundModes = audio, as follows:


    UIBackgroundModes

    audio

    ]]>

    However, since "batterygate" on iPhone4, Apple has been tightening its policy on applications that unnecessarily run in the background.  If the sound is supposed to play continuously (ex: music player), then they will * probably * be ok with it.  But if the sound is intermittent (even if it's the sound a clock radio alarm), they will likely ban.

    So, if you want your application to play intermittent sounds while in the background, your only chance is to configure notifications and associate a sound for notifications if you can.

    If you try the road local of notification, to help DONKEY of Juan Carlos Pazmino, however, that the sound function is broken right now, at least on iOS 5.1.1.  Also, at the time where he worked, I was not able to choose the sound through the app: I got was the standard "ding" sound.  Maybe push notifications are more robust.

    See you soon.

  • The next step in my game: could not get integrated sound in my addEventListener

    I tried to put the init() function in my loop in the fire, but it does not work.

    stage.addEventListener (MouseEvent.CLICK, myClickReaction);
    speeds the LONG NYPOTENUSE
    var v: Number = 5;
    var varObject:String;
    var i: Number;
    var arrayObjects:Array;
    var soundClip:Sound;

    complete table and initialize the variables i and varObject
    arrayObjects is ['chocolate', 'ice', 'pizza', 'Burger', 'sandwich', 'egg'];.
    i = 1;
    varObject = arrayObjects [i-1];
    trace (varObject);


    mouse click point
    var clickPoint:Point = new focus();
    function myClickReaction(e:MouseEvent):void {}
    clickPoint.x = mouseX;
    clickPoint.y = mouseY;
    addEventListener (Event.ENTER_FRAME, onEnterFrame);
    addEventListener (Event.ENTER_FRAME, enterFrameHandler);
    }
    function onEnterFrame(event:Event):void {}
    var xDistance:Number = clickPoint.x - sunny.x;
    var yDistance:Number = clickPoint.y - sunny.y;
    var angle: Number = Math.atan2 (yDistance, xDistance);
    Sunny.x += v * Math.cos (angle);
    Sunny.y += v * Math.sin (angle);
    If (clickPoint.x > = sunny.x) {}
    sunny.gotoAndPlay ("walk straight");
    trace (Math.ABS (xDistance));
    }
    If (sunny.x > = clickPoint.x) {}
    sunny.gotoAndPlay ("left foot").
    trace (Math.ABS (xDistance));
    }
    If (Math.abs (xDistance) < = 10) {}
    trace ("Works");
    sunny.gotoAndPlay ("static");
    removeEventListener (Event.ENTER_FRAME, onEnterFrame);
    }
    }
    addEventListener (Event.ENTER_FRAME, enterFrameHandler);
    function enterFrameHandler(e:Event):void {}
    If (sunny.hitTestObject (this [varObject])) {/ / this property refers to the referenced mc and it's an array you also need hooks}
    Init();
    i = i + 1; / / ie: he comes to the table object and NOT the string.
    varObject = arrayObjects [i-1];
    trace (varObject); / /, BUT you can draw the STRING IE: no need to use OBJECT (STRING) - that would be the real mc.
    removeEventListener (Event.ENTER_FRAME, enterFrameHandler) ;// IE: you can't do a hitTest on a string, BUT on an object. (The Bay)
    }
    }

    //var soundClip:Sound;

    function init() {}

    soundClip = new Sound();
    soundClip.load (new URLRequest ('< sound/chocolate >'));
    soundClip.addEventListener (Event.COMPLETE, soundLoaded);
    soundClip.addEventListener (ProgressEvent.PROGRESS, soundLoading);

    }
    init();

    function soundLoaded(e:Event) {}

    soundClip.play ();

    }

    function soundLoading(e:ProgressEvent) {}

    Insert here the Preloader information

    }

    If you're only terminates the loop when there is a positive placement test, you will need to use the loop.

  • Find the issue of my Mac

    Hello.

    I do not understand why my Mac find see my iMac, but is unable to see its location?

    + A sound was played on my iMac to my iPhone when I test the sound function.

    Please see the pictures on my preferences.

    PS: My iMac connected life ethernet no wifi, then?

    my iMac

    From my iPhone

    The location services on the Mac work only when connected to WiFi. It is not possible to locate it if it is connected to a wired Ethernet connection.

  • Satellite Pro L40 - how to move from a Vista to XP

    Hi all

    I would like some info on "how a Vista to XP downgrade?
    I have an original XP SP2. Please help...
    I tried before, but the sound does not work... help please

    Apreciate will please and thanks in advance.

    Hello

    Usually, you can find and get these fixes Windows on the Microsoft page.
    You can also try Google. Simply search for the KB888111 and KB835221.
    Many websites of third 3rd provides these patches too.

    I had the same problem in the past and resolved is to install the patches mentioned before installing the audio driver.
    As I remember, audio device marked with exclamation yellow must appear after the KB888111 and KB835221 and portable installation restart a new high definition.
    You must install the audio driver to get rid of yellow exclamation point and to get the sound functionality.

    See you soon

  • Black screen Qosmio F30-140 but Windows is running

    When I turn on the computer, the screen goes black, no bios, no boot options what so ever.

    After a while, windows starts (black). Sounds, functions, I can not even play winamp because its on a taskbar, so easy to push even without display...

    If inserting DVD disc, DVD starts and display works perfectly.

    According to me, is a problem with the drivers, because I was using CCleaner before and he cleaned a lot I think.

    The solution... is to get the system restored from the day before... but how to make it... without display

    Help, please

    Update of the problem...

    System Restore from two or four days back has not helped :(

  • Audio driver for Equium A300D not working or projection

    No idea how it happened to my computer is a new only 1 week and sound works perfectly well.

    All of a sudden it will use in reading and on computer but not in the record I could play to others on another program for example.

    Equium a300d on vista

    I tried the audio drivers from the Toshiba site, but nothing seems to work.

    Please help :(

    Hello

    If he worked several days ago then I guess this must be a matter of software
    I really put t understand what you exactly do but try to overthrow the BONE until the point of time at the beginning, when this sound function worked correctly.

    A question:
    Did you also check the sound settings in Device Manager?
    Select this check box.

    Go to devices-> sound Manager and check the second tab called record.
    There you have to right click and mark the two peripheral options see the disabled and do not show not connected peripheral.
    Then mark the new recognized audio devices and enable it.

    Further, you should try to update the BIOS because a lot of strange problems can be solved by the BIOS updated.

  • No noise (regular or touchpad) on my iPad 2 Air.

    Lockscreen & keyboard sounds are turned on, mute is not on. Sound works only with headphones (for applications), but YouTube works fine without them. Volume control does not "headphones" are used when they have been removed (I had this problem some time ago, but it fixed).

    Absolutely no tactile keypad sound, camera or a keyboard. No noise from lockscreen with or without headphones. I've just updated to iOS later.

    I've got my Fitbit connected via Bluetooth and that's it (I have no calls or messages enabled). It's really frustrating.

    All the solutions out there (I've done the research and found nothing)?

    FYI... I spoke with Apple cat and we did a "reset all settings." All my sound functions returned to normal. I suggest doing this before reset hard. Go to settings, general, reset all settings. You will not lose data, but you will lose all customizations.

  • Cannot read file WAV in 2013 of Labview

    Hi gurus of LabView

    I am a novice with some minimal experience with Labview.

    Quick summary

    In my experience, I am using Labview in the measurement of exercise device. I have not haveany wrong with the acquisition and display of the signal using NI USB-6008. However, I have an obligation to play a WAV file (generated by MATLAB) for the people the pace at a pace and the game is defective 4810 error saying the format is unknown. The WAV file (can be found here-metronome. TXT - but the extension. Change WAV. TXT select Download) plays in other players. Previous posts have not sufficiently addressed this issue.

    More details:

    An exercise device measure movement of reading of the Volt sensor and converts it remotely by a formula of calibration (simple y = mx + c). During the 3 minutes the person exercises - part in the attachedVI works great. However, a rhythmic ticking noise must play the Division pace for him. I created the file WAV sound functions MATLAB or play 8 kHz (attached). But it does not work no matter how many different ways I tried. Suggestions needed!

    I am running Windows 7 Enterprise, 2 GB of RAM, LABVIEW 2013

    Any help/suggestion/improvement is appreciated.

    -SM

    Thank you, Ilooked some information more and was able to play the file.

    Specifically, this Youtube video is great ride-

    http://www.YouTube.com/watch?v=ChSVf9lZ44k

    Also I write the VI which can play a WAV file when its path is given (attached)

  • Add step C/C++ DLL to "PlaySound" (winmm.dll)

    I have been searching the forum to try to find my answer and examples, but have not found a solution yet.

    I currently have a DLL that has a call to the Windows "winmm.dll" (Directory Windows\System32) system in a step ActiveX adapter, I can beep. (use c# and VB 6 code in the past)

    I use it mainly to play a sound to indicate that my code has reached a 'Fail' step for debugging.

    I am reorganizing my test systems to make them (there are 2 independent systems) so that I can check them in to TFS (source control) and allow them to be independent, absolute path using only the relative paths for the entire sequence and DLL calls.

    The problem I have is that I use the same process template for both, and I don't want to have an absolute path to the DLL that contains the 'Play Sound' function in the DLL.  The process model is called by TestStand top of the stack.

    I tried to access the "winmm.dll" to play the sound and the "mciexecute" function, but I can't step configured in my sous-suite ProcessModelPostStepFailure of process model.

    When you configure the Action step (as a "C/C++ DLL adpapter to the dll, I keep hitting roadblock that I get errors.)

    How to configure this adapter to match the function calls to the 'mciexecute '.

    Code c# uses system.media.SoundPlayer reference:

    This is called TestStand
    public static void PlaySound (String Path)
    {
    SoundPlayer spWave = new SoundPlayer (Path);
    spWave.Play ();
    }

    and VB 6 code is:

    Private Declare Function mciExecute Lib "winmm.dll" (ByVal FileName As String) As Integer

    '# Function to play a sound. Used to report errors, or whatever.
    Public Function Sound (ByVal FileName As String) As Integer
    ' Arg: filename is the full path to one. To play WAV file.
    "Play sound
    Sound = mciExecute ("Play" & FileName)
    End Function

    Is this possible in an adapter TestStand steps?

    "How mocking the adapter correctly call for the ' mciExecute ' function?

    Mike

    Humphrey is incorrect. You can call this dll directly from TestStand. Most of the function prototypes can be called directly from TestStand. However, you will need to manually specify the prototype since the dll has no type information for which TestStand can automatically get the prototype. Simply specify the prototype as shown in the screenshot1.jpg file (return value is a 32-bit integer, the parameter is a string C const). You can also call directly to the .NET API from .NET adapter as shown in the screenshot2.jpg file

  • F8 key will not open safe mode

    1. the F8 key does not (safe mode) when the computer is restarted.

    2. the Microsoft sound does not play at the start and stop of all other sounds functions work perfectly.

    SYSTEM

    o Windows XP (home edition)

    o IE 8

    o MS-DOS [version 5.1.2600]

    o Phoenix Award BIOS installed 4/2006 [last updated 11/29/04]

    o Custom built computer, 5 years

    o no backup is available for crtical/discrete programs or the operating system OEM

    That someone has suggestions for the system difficulty and that everything remains alive.

    I think you need to determine if the problem of access to the SafeMode because that the F8 key does not access safe mode menu or the computer does not start in safe mode.

    In the past with a Microsoft Wireless Multimedia keyboard, I met the situation where the function keys had to be activated by pressing the CAPS LOCK key. This was to be done whenever the computer is started. This is done using the F8 key safe mode access impractical because you must press the lock key when the system is unable to receive instructions from keyboard and always press the F8 key until the system has progressed beyond the point where the ability to access the security mode is still available.  You can't do it.

    http://jtsang.MVPs.org/flock.html

    The easiest way to access the safe mode becomes to connect using a wired keyboard ps2 if you cannot access the mode without failure of the normal mode. To access the normal mode by selecting Start, run, type msconfig and press ENTER. Choose the Startup tab and let secure boot. Click apply and then click OK and restart the computer. To return to a normal startup, you uncheck the safe boot option.

  • When a character appeared reading serial port

    How to wait for some specific characters occurred in the serial port (e.g. port COM1 RS232 on PC) and then they recover at the port?

    I want to communicate back with a motor controller that uses ASCII strings such as commands and responses. It formulates a response to any command sent, and the response contains exactly a termination character (that I can specify during installation) at the end of the response string. Sometimes also, it sends a message when there is no order issued, for example a disc error message. There is no simple way and reliable when the controller is going to speak, when he won't, and the message will be exactly how many time, but we do know that each message will have this stop only at the end character. I would like to interpret the entire message in my code, that is to say, I would like to retrieve the string of all the characters from the previous endpoint character up to and including the most recent stop character. I think it means that I would have a VI that returns the message string and does not stream until the stop character appeared and was added to the response string. Or, Alternatively, a loop that adds entire messages to a queue of strings.

    All the screw example I found seems to rely on a certain number of milliseconds to wait or to know how many bytes to read, in order to use VISA Read.

    So far, I use a loop which seeks bytes in the buffer, retrieves everything to add to a string of shift register and test if there is a character of the string endpoint, all extract up to and including the stop character, if so. This feels very awkward and expensive for what should be a common task. Is this general law approach, or did I miss something in a simpler way?

    I read on the communication by Message and characters of endpoint, approach that sounds functionally similar to this, but it seems around standards of SCPI and my motor controller does not support this. In any case example Finder does not get a single hit on 'Message '.

    Thank you!!

    It really looks like you are doing things a lot more difficult it must be. Look at the VISA configure Serial Port. It has a character of endpoints allow and end characters entries. If you wire a real (or leave that he unwired) entry activate, read VISA will end automatically when you specify the stop character is detected. As long as the number of bytes to read is larger that the largest string that you expect to read, there is nothing else you need to do. That's how examples of shipment are put in place and discussions about the characters of the termination. Should there be nothing related to sustainable intensification of CROPS. If you do not get a message in your specified time-out, you get a time-out error.

Maybe you are looking for