Sound in AS3 class

I'm still learning AS3, and I was woking with sounds. This was to be used to stop the cound assigned to the var channel 1 when I click on the button, the sound is muffeled just, but can't stop playing. Anyone knows there is a problem with flash running in Windows Vista?

Here is the code:

Stop function
function stopClick(evt:Event):void {}
CHANNEL1. Stop();
}
bStop.addEventListener (MouseEvent.CLICK, stopClick);

Thank you

I thought about it. When I added the soundLoaded function, I thought that I deleted the. play() and the head of my code. Now it looks like this, and it works.

Creates a var musicURL and assigns it the name of location of background music.MP3
var musicURL:URLRequest = new URLRequest ("background music.MP3");
Creates a sndMusic var and pointing to the location of musicURL
var sndMusic:Sound = new Sound (musicURL);
Creates a SoundChannel var
var channel1:SoundChannel;
Play the sndMusic and assigns the soundChannel for channel 1

function errorMsg(evt:IOErrorEvent):void {}
trace ("the sound could not be loaded");
}
sndMusic.addEventListener (IOErrorEvent.IO_ERROR, errorMsg);

function soundLoaded(evt:Event):void {}
trace ("Sound Complete");
Play the sndMusic and assigns the soundChannel for channel 1
CHANNEL1 = sndMusic.Play ();
}
sndMusic.addEventListener (Event.COMPLETE, soundLoaded);

Stop function
function stopClick(evt:Event):void {}
CHANNEL1. Stop();
}
bStop.addEventListener (MouseEvent.CLICK, stopClick);

Start function
function playMusicClick(evt:Event):void {}
CHANNEL1. Stop();
CHANNEL1 = sndMusic.Play ();
}
bPlayMusic.addEventListener (MouseEvent.CLICK, playMusicClick);

Thank you. I hope this will be useful for anyone else making the same mistake I did.

Tags: Adobe Animate

Similar Questions

  • Can extend us the document class with a custom flash as3 class?

    Hello
    Can extend us the document class with a custom flash as3 class?

    Thank you
    Mallek

    Try:

    amishap67776642 wrote:

    package

    {

    public class accessories extends ScreenBase

    {

    public void accessories()

    {

    Super();

    addEventListener (Event.ADDED_TO_STAGE, onAddedTostageHandler)

    }

    private void onAddedTostageHandler(e:Event):void

    {

    Super.init ();

    }

    }

    }

    / * class ScreenBase * /.

    package

    {

    SerializableAttribute public class extends MovieClip ScreenBase

    {

    public void ScreenBase)

    {

    Super();

    }

    public void init (): void

    {

    MovieClip (that).tutorialBox_mc.visible = true;

    }

    }

    }

  • Stop sound in AS3?

    I heard that stop sound in AS3 to write specific code. I don't know what this code is, then, if anyone of you knows it please tell me because I would like to be able to stop a song in a game on the following image. (For example, frame 2)

    This depends somewhat on your configuration, but in general you play a sound in a sound channel object... and you can tell channel.stop (); to stop the sound. Or you can use the SoundMixer object to stop all sounds in the film. Take a look using the SoundChannel and Sound, they have good examples.

  • How to open a Popup from an AS3 class

    I have a standalone AS3 class (does not inherit from any other class).

    I want to show a pop-up window from the inside of this class using the PopupManager addPopup (or createPopup). Problem is that the two methods require a class iFlexDisplayObject to indicate where to add the popup at.

    Is there a static property/function that would give me my application object (any object to display on the stage will do).

    Something like Application.application would be perfect, but unfortunately there is no application for this class (at least not with 2.0.1).

    I scoured through all classes but could not find something to help.

    Because now I'm passing (this or Application.application) as an argument to the constructor of class so it can be used later to instantiate the Popup.

    Any help or pointer is especially appreciated.
    TIA
    Julio

    Thanks for the reply, but I found a solution to my problem.

    I tried to use this construction:
    App: application var = Application.application;
    PopUpManager.addPopUp (mypop, app);

    Which caused an error of execution for some reason any "app" has not been, he was always null.

    Then someone suggested that I qualified assignment. I changed it to the following, and now it works as expected:
    App: application var = Application.application as Application;
    PopUpManager.addPopUp (mypop, app);

    go figure, at least, I now have a way to access the best application around.

    HTH
    Julio

  • To access the objects placed directly in the fla of the as3 class file?

    Hello

    I'm pretty new to flash and I do this game were traveling along a track and along this trail, there are a lot of boxes, I want my character to pick up.

    Now my question is, is it possible to use a symbol in the library and just place it on the track directly in the fla. folder and then power it hitTest with the character, I added in the as3 file?

    I hope I did, it's understandable.

    Thanks in advance!

    Sincerely of Smith

    Is your code in a separate class? If so, simply extend a display object (for example public class Foo extends Sprite). Then, you have access to the scene, as well as objects in the timeline panel.

    The code for hittest is quite simple. Continually check the hitTest, a test against an another movieclip movieclip method to see if it returns true. How do optimize you how many tests is performed are up to you. Management if the person is on the path you will help understand what are the objects to test against.

  • Help with the AS3 Classes and packages

    Hello

    I'm trying to see if I can implement a function of speech synthesis in Flash. I found this post, which explains in detail how to integrate Google with Flash text-to-speech functionality. Looks pretty good, but the post seems to be written for programmers in AS3 uber-genius... Well not really, but at least those who already know how to assemble these pieces.

    I know a little about the use of the classes and packages, but do not understand how all segments of code in his position could be stitched together.

    No chance anyone can check this and give me a basic overview of how all these pieces go together? So I can try to implement myself...

    http://blog.onebyonedesign.com/ActionScript/Googles-text-to-speech-engine-in-Flash/

    Thank you very much in advance!

    Elliott

    PS. also open to an alternative to speech in Flash, if you know a easier... Thank you!!

    Here's a link to something that might be useful for you as well as to learn how to work with custom classes.  I don't think I've ever seen of it, but it was mentioned in another of tutorials from Lee that I watch and that it helped me anyway.

    http://gotoandlearn.com/play.php?id=30

    Insofar as the page you will bound, that third largest section of the code (the class named hand) is basically what you want to use for any Flash file you have on your page that provides the interface text/speech.  Then you would copy to a file named "Main.as" you have in the same folder as your swf file and use it as your document class.  The document class is specified in the properties of your fla Panel.

    One thing about this file, it's that I can't import the file "GTextToSpeech.as" that he uses.  So, you may need to add as an import at the beginning of your Main.as file.  The file GTextToSpeech.as is it that you would name the file you create using the first section of the code on this page.

    This small second section of the code, this is what you will place in a php file.  According to the file Main.as name this php file should be "proxy.php".  This file must be in the same folder as the html page that loads the swf file.

  • sound help AS3

    Hey people,

    I'm a guy more old as2, switch to full as3. Now, I want to do everything I can in as3. My final hurdle is healthy. I can get sound to play, but I can't add a delay to the sound. So, when I picked up the item to drag, it lifts and I delay using a Tween Oregon to make it appear more life like. I would like to delay the sound piece for the duration of the item down. I have attached the section of the code. Any ideas would be great. I know that I could add sound space for the mp3 itself but as part of my project that would be crazy.

    var I: Object;

    function grabMe(e:MouseEvent):void {}

    = me e.currentTarget;

    me.removeEventListener (MouseEvent.MOUSE_DOWN, grabMe);

    me.startDrag ();

    e.target.parent.addChild (e.target)

    var tweeny:Tween = new Tween (me, "y", Regular.easeIn, me.y, me there - 75,.04, true);

    var scaley: Tween = new Tween (me, "scaleY", Regular.easeIn, me.scaleY, 1.3,.09, true);

    var scalex:Tween = new Tween (me, "scaleX", Regular.easeIn, me.scaleX, 1.3,.09, true);

    var my_shadow:DropShadowFilter = new DropShadowFilter();

    my_shadow.color = 0x000000;

    my_shadow.blurY = 3;

    my_shadow.blurX = 3;

    my_shadow.angle = 90;

    my_shadow.alpha =. 2;

    my_shadow.quality = 15;

    my_shadow.distance = 75;

    var filtersArray:Array = new Array (my_shadow);

    me.filters = filtersArray;

    stage.addEventListener (MouseEvent.MOUSE_MOVE, Drachma);

    stage.addEventListener (MouseEvent.MOUSE_UP, dropMe);

    }

    function dropMe(e:MouseEvent):void {}

    stage.removeEventListener (MouseEvent.MOUSE_UP, dropMe);

    stage.removeEventListener (MouseEvent.MOUSE_MOVE, Drachma);

    me.stopDrag ();

    me .filters = undefined;

    var tweenydown:Tween = new Tween (me, "y", Regular.easeIn, me.y, me there + 90,.4, true);

    var scaley: Tween = new Tween (me, "scaleY", Regular.easeOut, me.scaleY, 1,.9, true);

    var scalex:Tween = new Tween (me, "scaleX", Regular.easeOut, me.scaleX, 1,.9, true);

    me.addEventListener (MouseEvent.MOUSE_DOWN, grabMe);

    my_channel = my_sound.play)

    }

    function dragMe(e:MouseEvent):void {}

    e.updateAfterEvent ();

    Using TweenLite or Max, you just make your tween and add an onComplete parameter as follows:

    TweenMax.to (me, 2, {onComplete, scaleX:2:playSound});})

    This will tween me is scaleX for more than 2 seconds and call the playSound function when it ends...

  • Slaughter of BG sound with another class please help!

    Hey hope someone can shine a light on this for me, been stuggling with that for awhile now.

    I had a background sound to play, which is in a separate category codes:

    Class: screen_Control

    public function randonizer_SND (): void

    {

    var r: int = Math.floor (Math.random () * 17);

    if (r == 1)

    {

    currentBG_SND = snd1_BG;

    }

    if (r == 2)

    {

    currentBG_SND = snd2_BG;

    }

    if (r == 3)

    {

    currentBG_SND = snd3_BG;

    }

    if (r == 4)

    {

    currentBG_SND = snd4_BG;

    }

    if (r == 5)

    {

    currentBG_SND = snd5_BG;

    }

    if (r == 6)

    {

    currentBG_SND = snd6_BG;

    }

    if (r == 7)

    {

    currentBG_SND = snd7_BG;

    }

    if (r == 8)

    {

    currentBG_SND = snd8_BG;

    }

    if (r == 9)

    {

    currentBG_SND = snd9_BG;

    }

    if (r == 10)

    {

    currentBG_SND = snd10_BG;

    }

    if (r == 11)

    {

    currentBG_SND = snd11_BG;

    }

    if (r == 12)

    {

    currentBG_SND = snd12_BG;

    }

    if (r == 13)

    {

    currentBG_SND = snd13_BG;

    }

    if (r == 14)

    {

    currentBG_SND = snd14_BG;

    }

    if (r == 15)

    {

    currentBG_SND = snd15_BG;

    }

    if (r == 16)

    {

    currentBG_SND = snd16_BG;

    }

    playSND();

    }

    public function playSND (): void

    {

    snd_BG_Channel = currentBG_SND.play (0,1);

    snd_BG_Transform.volume = 1;

    snd_BG_Channel.soundTransform = snd_BG_Transform;

    snd_BG_Channel.addEventListener (Event.SOUND_COMPLETE, nextSnd);

    }

    nextSnd(event:Event):void of the public service

    {

    randonizer_SND();

    }

    Is what I try to achieve this sound to stop playing when a "button" is linked and then start playing again back in the main screen.

    The "button" is controlled in a different category, and when I try to put a stop function there is to the sound I have the following error:

    1119: access of property may be undefined snd_BG_Channel through a reference with static type class.

    This is the code I use to try to stop the channel:

    screen_Control.snd_BG_Channel.stop ();

    If you have an idea of what I'm doing wrong please help!

    THX pavel

    Did you check this line? public var snd_BG_Channel:SoundChannel;

    Must be:

    public static var snd_BG_Channel:SoundChannel;

  • IncorporerPolices in AS3 class

    I can't find anything to say or not am I to use the class name given when I export the police for Actionscript. I did it when you set up my stylesheet, but it doesn't seem to work. Is there something new I missed with AS3?

    have you used 'AGBookBQ support' when you set the property to make your textformat instance?

  • How to play sound in AS3

    In AS2, you can listen to sound through s.loadSound("mysound.mp3",true) where the second loadSound parameter indicates that you want the sound.
    How do you do this in AS3?
    Thanks for your help.
    Ken

    When you run your load(), the audio file begins to download. who will continue unless you run a close() method.

    your sound will start playing when you run, you're your play() method or after the bufferTime is met, the first of the two prevailing.

    the real question is how do you keep streaming in as3. and who is easy to aid sound complete event to trigger the play() method. If the play() method is executed while loading is complete AND bufferTime is lower than the charging time, your sound will flow.

  • How to enter the master as3 classes?

    OK I am trying to use an item in list to the Director, but I encountered a small problem.

    I have my cellRenderer class I built and tested in AS3, how do I get it in Director?

    In the not so useful help files, it reads:
    With the help of Director / using Flash, Flash components, and other Interactive Media Types / list component

    List.cellRenderer assigns the class or the symbol to use to display each line in the list.

    How? Any ideas?

    See you soon!

    -Dan

    Director 11 is NOT compatible AS3. It does not support the a bit. It does not support any part of AS3. If you use AS3 in your Flash animation and import or link this Flash movie to a movie Director 11, then your Flash animation will not work correctly.

    This will probably change in the future with an update to the xtra Flash, but as of this writing, AS3 DOES NOT DO WORK in the films of Director 11.

  • Stop all sounds in as3? Help

    When the game starts. I have the toggle button. I can play a sound or stop the sound. When I play the sound, of course it is not cut so even if I go to the next page. I can reason that the sounds will play always.

    But if I press the no sound, so it means it must be cut... on the first screen, the sound stops. But when I next executives and others. The sounds are playing. The sound on the screen

    looked like

    var test: Sound = new NameOfSound();

    but in the next... the sound is in the framework itself... no declarant as the first screen...

    and also some sounds play when something happens or for example if the ball hits the target collsion... good reading...

    I tried to have the solution as in the first screen if for example she is silent... I'll set it to trueStop... then on the following frameworks... I would put:

    if(trueStop == true) {}

    SoundMixer.stopAll ();

    }

    in this way the framework seems stopped and functional... but sounds to join the service when as I said if a collision occurs, the sound plays again... arrgghh I can not explain clearly... I hope you understand my problem...

    any ideas?

    If you need to stop the individual sounds, assign a soundchannel for instance returned by your method of reading and apply a method to stop this soundchannel.

    for example:

    var s1:Sound = new S1();

    var sc1:SoundChannel=s1.play();

    now, anytime you can use:

    SC1. Stop();  to stop the s1 only.

  • Documentation from Adobe about the AS3 Classes

    Hello

    In this Adobe Web site link:

    http://help.Adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9 b90204 - 7f30.html

    He discusses the constructor methods. They give this as an example (see below):

    Class Example
    {
    public var: string State;
    public function Example()
    {
    status = "initialized";
    }
    }

    var myExample:Example = new Example();
    trace (myExample.Status); output: initialized

    The question is can this code written that what, or am I supposed to know that I have to do the following:

    1 rewrite the class and put it in a package statement and save it as Example.as

    2. create a Fla file and place it in an import statement and the code where the instance is created.

    Thank you

    Jim

    P.S. If the code can run as is, how do you do that simply by pasting all the code in a FLA file.

    you answered your own question.  you are right you need to package and need to import each place you use.

    While the package by the way, this is where your class is living in what concerns the fla.   If you set your fla to look at a folder and this folder is where your class, your package is then just the package {}

    If you set your fla to look at a folder called src, and you have your folder src has a folder called your documentClass then your package is {package.documentClass}

    If you do not have the FLA pointing to any folder, and that you do not have a folder structure for your class you can just write {package

    and import would be exatcly, as it appears in your package.

    Import documentClass.Example () or good Example()

  • cannot access the properties of the AS3 class stage

    Please take a look at the attached code. It is throwing this compilation error:

    1120: access of undefined property scene

    no idea why?


    cool SymTsb, who works a treat. question: why not the documentation makes this clear? or I didn't just rush-set-read it?

    I have a getter in my main Application class which returns the root mc as a 'context', so I can't ride the thing, this line works perfectly:

    MyMainApplicationClass.context.stage.frameRate;

    I greet you all SymTsb

    :)

  • sounds in AS3

    I tried to use this code-

    var soundReq:URLRequest = new URLRequest ("Z.mpg");
    var on wood: Sound = new Sound();
    woodblock. Load (soundReq);

    a.addEventListener (MouseEvent.CLICK, Pick-up);

    function pickUp(event:MouseEvent):void {}

    woodblock. Play();
    }

    And got this error:

    Error #2044: Unmanaged by the IOErrorEvent:. Text = Error #2032: error flow.
    to a_fla::MainTimeline/frame1() text

    Could someone point me in the right direction to make this work? Thank you!

    I answered my own question, for someone else in this situation, you must use an MP3 file.

Maybe you are looking for