Actionscript 3 :: Playing Sound From Library With Name From String?
Aug 25, 2010
I am trying to write some actionscript 3 code to play short sounds from the library, using a dynamically created string to load it. In AS2, I could do something like this:
mySound = new Sound();
mySound.attachSound("any concatenated string" + foo);
In AS3 however, the identifier is a class whose name, it seems, must be already known. Is there a simple way to 'attach' a sound using the identifier as a string in actionscript 3?
I have a sound clip that I'm loading externally into my flash file. The code I'm using looks like this and is placed in the as layer on the first frame,
var mySound:Sound = new Sound(); var myChannel:SoundChannel = new SoundChannel(); var myTransform = new SoundTransform(); var lastPosition:Number = 0; mySound.load(new URLRequest("introaudio.mp3")); myChannel = mySound.play(); [Code]....
I am creating a game that has 6 movieclips all on the main time line of the game. Each movie clip has three buttons that when clicked plays, pauses or stops a sound clip.When I press any of the sound clip play buttons that sound starts playing, the problem is when I click any of the other sound clip play buttons those sounds also start to play. Is there a way I can disable the other sound clip buttons while the current sound is playing then enable all of the buttons when the current sound has stopped.
This is the code that creates one of the sound objects
So I made a few buttons with sounds within them and when I publish it they work just fine. But what I want them to do is;
Say I click a Button.The sound starts playing.Then I click it again, before the sounds done playing.I want it to stop the playing sound and start playing the button I just clicked on, whether it be the same button, or a different one.Right now it just ends up sounds like an echo because it'll play it as many times as you click it.
I'm trying to play a sound using a technique found here (play the sound by sampling raw sound data gathered from the original with extract()), with the difference that the mp3 sound is embedded in the swf, not loaded externally. This is my code:
var soundBytes:ByteArray = new ByteArray(); var mp3sound:Sound = Sound(new Sound1_design()); // this is the embedded sound mp3sound.extract(soundBytes, int.MAX_VALUE);
[Code]....
This works, in a way, except that the resulting sound is distorted (it has a kind of a metallic ring).
I am loading small sounds dynamically with the loadSound command. These small sounds are activated with a rollover. see script below. This works ok. however. i want the first sound to keep playing while the rollovers load sound. a bit like playing the piano. This works ok when i import all the sounds into the library and place them on their very own button. however the size of the flash movie increases to 140k. whereas when i load them dynamically the size of the movie is 20k. obviously i want to load dynamically.
But with dynamic loading each sound stops when another sound is rolled over, so that there is only ever one sound playing at once. I need to load the sound into a different level or something, so that the first sound can keep going while the smaller, shorter sounds play over the top. this is my script below. The first sound loads when the movie starts. This is the one i want to keep playing. Then there are the smaller ones with rollovers. does this make any sense? there's actually 13 little sounds.
ok so i have a button that plays an animation for fire when held down. and when realsed goes to and stops and frame one. when it reaches the end of the time line it goes to and plays at frame 10 and goes back to the end of the timeline. I have a sound for the fire animation that plays for the effect. The problem is the sound keeps going untill its over even if the button isnt held down. and when the playhead reaches the end of the timeline it goes to and plays and frame 10 and it replays the sound. if i hold it down it will just keep playing the sound over and over from start to finish. what i want it to do it when i hold the button down i want it to play the sound and when released it stops the sound where ever it is at. I also dont the sound to play again if there is a sound already going to stop it from playing 20 sounds at one time it gets loud and you need asprin after about 5 seconds of that.
I am trying to embed some sound controls, and have hit a dead end. I made my play and stop buttons, imported my mp3,, assigned it proper linkage, and inserted this AS2 :
[Code]...
The buttons are named "play_btn" and "stop_btn" respectively. When I export it or preview it, hitting the play button does not do anything.... I hear no sound. What could be up with this?
I'm playing the game League of Legends and I decided to make an iPhone application that let's you pick a champion (a character in the game)picture and play the sound for it. I downloaded all sound and images, loaded them into the library, and now I only made 4 champions just for testing.This is my code for AS3 when you click on the button to play the sound.[code]When you click on the picture again, It will play the sound once again and if you mass click it will mass play it (I want it to stop playing current one, then start playing the new one if you double tap it).When you click on 1 picture, it will make the sound, ok.. but when you click on ANOTHER picture, It will play the second image sound AND the first image sound together (Mixed up. I want it to make it so it stops playing the first one, then plays the second one).
Is there any lib for playing MKV (matroska) in flash (AS3, MXML) OpenSource or KindOf opensource? (In my MKV I have Theora video H264 video... If library supports only 1 type of video codec Ill live with that=))
Is there anyway to use the playback components to play a video imported into the library? (The .swf I'm creating has to be stand alone so I need the video to be imported). Also can the component video skins be imported also?
I'm using a CLICK event to add a MovieClip to the stage from my library. Within the added MovieClip is a child MovieClip animation with a stop() on it's first frame.For some reason when I add the parent MovieClip to the stage on CLICK, the child clip immediately starts playing, even though it has a stop() on it's first frame. This is how I'm doing it:
Code: Select allstage.addEventListener(MouseEvent.CLICK, mouseClick); function mouseClick (event:MouseEvent):void {
Im making an animation and in the 3rd scene i have a deer that screams and the sound plays way to early. I had to drag it out way past the frame where it opens its mouth for it to play at the right time.
I have no idea whats wrong this has happened before. I really dont want to have to guess on where to put the sound for everything a character says.
Back to my nightmare project, I've embedded sounds in the project that play based on certain user actions. They play fine for me (PC), but my customer is telling me they don't work for her (Mac).Would there be ANY reason a sound would play on a PC but not a Mac?I've told her to update her Flash player to make sure it's current and to make sure her speakers are on and the volume is up, but no sound.Okay, the REAL reason this isn't working is user error based on everything else I'm told that's happening and not happening, but I need to cover my bases and see if there really may be a reason sounds won't play on a Mac.
I´ve made a site for myself in flash (AS 2) and it works great. But one thing that I havent got the knowledge for is that I would like to have my own sound library.Anyway what I want is a xml updatable library, a simple list of sounds for visitors to download for free! A preview of the sound is also something that I need. The sounds are mostly very short sounds, so a rollover should work i think.[code]If there is someone here who would like to help me with this? Just to get me started. I fully understand if someone here thinks like, wow thats alot to ask for! how rude and so on, but if there is someone that maybe thinks that this could be fun or interesting and would like to give it a shot.
I am trying to load a movieclip from the library onto my stage. But the name of the movieclip is read in from a user-entered text field. Typically, to load a movieclip from the library named, Bee, I would do the following:
var mc:MovieClip = new Bee; // this works.
But the name of my symbol is in a TextField. The following do not work:
// Attempt #1: var mc:MovieClip = new userfield_txt.text; // No Good // Attempt #2: var str:String = userfield_txt.text;
[code]....
I realize the new operator requires a Class data-type, so how do I get the value stored in a String or TextField into a Class type?
I have some movieClips in my libaray called p1, p2 etc with export settings of the same name.I have the names stored in an array.I cant work out how to do this dynamically:
ActionScript Code: private var myImages:Array = [p1, p2, p3, p4, p5]; private function changeImage(newImg:Number):void {
I want to load one out of 18 different instances from my library (exported as mc1-mc18). In AS2 this was simple! I fetched the variable (whC) that contained the name of the movieclip to be loaded and just put it into attachMovie
I have a playhead that moves across the screen and when it hitTests a movie clip it plays a sound. all is working fine except that it will only work the first time it is played. The playhead is controlled by a button. I am working in Actionscrpt2. Here is the code on the movieclip:
onClipEvent(enterFrame)[code]....
In the begining I was having trouble because the hitTest was playing the sound over and over but the above code sorted that out. I think that the new problem was created by fixing the old one.
I want to achieve the effect of a computer startup. IE, it only plays -once- and then doesn't play again for the rest of the time, even if the user comes back to the same menu. How do I get Flash working that way? I've tried variables to no effect... it doesn't want to change the variable condition.
I have another one to get off my chest.I am basically doing a spinning wheel game - i want the sound to play each time the Stopper hits a new prize section of the wheel.In my code, from my EnterFrame function, i call my playSound function but the sound file just never plays .. i know the function is being called as i can see it in trace.I suspect that because the EnterFrame is constantly being called, that the sound file - because it has determined it won't complete - it ignores it totally.[code]
Anyone know why this keeps playing the same sound over and over?
If I call it using: Code: var sounds:src.snd.SoundManager = new src.snd.SoundManager(); // This isn't how I do it, but ... you understand. sounds.queueSound('libsound1');
I have a small sound effect (less than 10KB) I have placed on my timeline. When I test it directly in flash, I can hear the sound effect, but when I CTRL + test my movie, I can't hear the effect?
How can I edit sound from a timeline if I don't have the original sound file? When I right-click my sound in the library, I can't open it in any sound editor program. What do I do?
having real problems finding anything about fading in and out sound in flash, have searched for 3 days now and found mostly as2 related articles,i have the following
var myintSnd:introSound; var sndintChannel:SoundChannel; myintSnd = new introSound;
In Flash 10/AS3, I added some sound and it seems to be working alright, but I think I'm doing it wrong. I imported the sound into the library, but I believe that it's reloading it from the folder with the swf/sound. I'm loading them like so:
I have to play some sound on a webpage with javascript, and probably flash is the best choise, so i created an swf library with mi sounds wit swfmill [url]...[code]...