Soundboard Help! - Convert AS2 to AS3 - Stop All Sounds On button release
Im making a soundboard and I chose AS3 by accident. What I need the code to do is STOP the CURRENT sound from playing
if another is pressed.
the code that worked for AS1 and AS2 was
onMouseDown = function () {
stopAllSounds();
I tried messing around with this in AS3:
import flash.media.SoundMixer;
"mouseUp" (MouseEvent.MOUSE_UP), "click" (MouseEvent.CLICK)
SoundMixer.stopAll();
but It doesnt do anything.
import flash.media.SoundMixer;
SoundMixer.StopAll();
^^^
plays the sound once and messes the sound up after playing for only half a second or not at all
thanks a lot for help
this as2 code:
onMouseDown = function () {
stopAllSounds();
// would be the following in as3:
this.addEventListener(MouseEvent.MOUSE_DOWN,f);
function f(e:Event):void{
SoundMixer.stopAll();
Similar Messages
-
Help Converting AS2 to AS3 Drag and Drop Event
Hi All,
This is the second post on help for converting AS2 to AS3. This code is used in Captivate to allow a drag and drop action between two areas (User presses down, drags, and releases in a second area - They are not dragging any object). If anyone can help me convert this please let me know.
Source for Drag and Drop: (Note: Single MovieClip)
// pause the Captivate movie
_root.rdcmndPause = 1;
// when the user's mouse is let go check if there was a successful drop
_root.onMouseUp = function(){
// If the source area's center coordinate is nearby the destination area's center coordinate then advance the slide
if ( Math.abs(_root.sourceX + _root.sourceWidth / 2 + _root.sourceParentX - (_root.destX + _root.destWidth / 2)) < (_root.destWidth / 2) &&
Math.abs(_root.sourceY + _root.sourceHeight / 2 + _root.sourceParentY - (_root.destY + _root.destHeight / 2)) < (_root.destHeight / 2) )
_root.rdcmndNextSlide = 1;
} else {
// show error movie clip for 2 seconds (60 frames at 30 frames per second)
_root.showErrorMessage = 60;
mc.onEnterFrame = function(){
// continuously update the source area's coordinates and size
_root.sourceX = mc._x;
_root.sourceY = mc._y;
_root.sourceWidth = mc._width;
_root.sourceHeight = mc._height;
_root.sourceParentX = _parent._x;
_root.sourceParentY = _parent._y;
mc.onPress = function(){
// Uncomment following line to have control click capabilities
//if(key.isDown(Key.CONTROL))
// when user clicks on the source area click start the drag
startDrag(this);
mc.onRelease = function(){
// stop drag when user releases the source area
stopDrag();
Source for Destination Area (Single MovieClip named destArea)
// Set a root variable to control when the error message is displayed
_root.showErrorMessage = -1;
// Use setCoords variable so we only set the destination coordinates once
var setCoords = 0;
destArea.onEnterFrame = function(){
if (setCoords == 0){
// set the destination x, y, width, and height
_root.destX = _parent._x;
_root.destY = _parent._y;
_root.destWidth = _parent._width;
_root.destHeight = _parent._height;
// destination coordinates have been set, change setCoords so it doesn't get set again
setCoords = 1;
Code for the Error Message (Single MovieClip named errorMessage)
// Don't display the error message initially
errorMessage._alpha = 0;
errorMessage.onEnterFrame = function (){
// If the drag and drop method detects a missed drop
// then show this error message by setting _alpha to 100
if (_root.showErrorMessage > 0){
errorMessage._alpha = 100;
// decrementing this variable controls the time the
// error message will be displayed
_root.showErrorMessage--;
} else {
// Don't display the error message
errorMessage._alpha = 0;use:
MovieClip(parent.parent.parent).rdcmndPause=1;
this.addEventListener(KeyboardEvent.KEY_DOWN,keydownF);
function keydownF(e:KeyboardEvent):void{
fscommand("KEYPRESSED", e.keyCode);
if(e.keyCode==32){
MovieClip(parent.parent.parent).rdcmndNextSlide=1; -
Help Converting AS2 to AS3 (Spacebar Action in Captivate)
Hi All,
There seems to be a lot of these posts on this forum so I thought I would see if anyone could help me out. I had some code developed for me that was in AS2 and I need this in AS3 due to the upgrade in software. Below is the AS2 code:
_parent._parent._parent.rdcmndPause = 1;
myListener = new Object();
myListener.onKeyDown = function () {
fscommand("KEYPRESSED", Key.getCode());
If (Key.getCode() == 32)
_parent._parent._parent.rdcmndNextSlide = 1;
EndIf
Key.addListener(myListener);
The code is simple really. It was suppose to allow the Spacebar to be used as an input key to go to the next slide in Captivate. There is a single MovieClip in the file. Please let me know.
Thanksuse:
MovieClip(parent.parent.parent).rdcmndPause=1;
this.addEventListener(KeyboardEvent.KEY_DOWN,keydownF);
function keydownF(e:KeyboardEvent):void{
fscommand("KEYPRESSED", e.keyCode);
if(e.keyCode==32){
MovieClip(parent.parent.parent).rdcmndNextSlide=1; -
Please need help converting AS2 to AS3 code
Hi, I want to convert an AS2 code to AS3. Someone can tell
what is wrong. (it is about a speed effect) - Thanks a lot.
mport flash.filters.BlurFilter;
import fl.transitions.Tween;
import fl.transitions.easing.*;
var duration:Number = 15;
var t1:Tween = new Tween(mcToTween1, "_x", Elastic.easeIn,
133, 367, duration, 0);
var t2:Tween = new Tween(mcToTween1, "blur", Elastic.easeIn,
0, 0, 1, true);
t1.onMotionChanged = function() {
oldx = x;
oldy = y;
x = mcToTween1._x;
y = mcToTween1._y;
speedx = Math.round(Math.abs((x-oldx)));
speedy = Math.round(Math.abs((y-oldy)));
mcToTween1.filters = [new BlurFilter(speedx*2, speedy*2, 1)];
trace(speedx);
t1.onMotionFinished = function() {
t1.yoyo();
};use:
MovieClip(parent.parent.parent).rdcmndPause=1;
this.addEventListener(KeyboardEvent.KEY_DOWN,keydownF);
function keydownF(e:KeyboardEvent):void{
fscommand("KEYPRESSED", e.keyCode);
if(e.keyCode==32){
MovieClip(parent.parent.parent).rdcmndNextSlide=1; -
Hi everybody,
i load external swf to the main movie. They all have sound. Have no problem to stop sound of the main movie (by the behaviors), but it doesn’t stop the sound of the external one. What AC should be used to stop all sound, external and internal?
Thanks
Sbelieve it or not, you nearly hit it right on the head! lol under AS2 the line is: stopAllSounds();
-
How to stop all sounds in root
Sorry I am a newvby to Actionscript. I found the following script for a button which let me stop all mc inside the root but I need to stop all sounds in the root as well.
Any help is appreciated.
Thanks
on (press) {
getAllMc(_level0);
function getAllMc(mc) {
for (var i in mc) {
if (typeof mc[i] == "movieclip") {
mc[i].stop();
getAllMc(mc[i]);You can use the stopAllSounds() function
-
LOVE LOVE LOVE my iPhone so far, but ringer switch doesn't stop all sounds?
With exception of a few concerns like somewhat low speakerphone and earpiece volume, no non-pinch zooming in maps, not being able to expand email contacts (to see the actual address), not having any auto-fill in Safari, and some stability issues (a couple Safari crashes on complex sites - to be expected until they collect enough bug data and make a patch)... I love my iPhone! After updating my OS & iTunes, activation took only a few minutes (early evening of the 29th) since I was an existing account holder. I did have a corporate discount on my plan and was worried I would be denied, but it went through just fine - fwew!
So then, I'm in a movie theatre today during a dramatic, quiet passage, with the ringer switch off (I'm so polite! <bg>), and low and behold, here comes a clever marimba roll. Having not heard this other than in the ringer setup area, I wasn't sure what it was (still not). Hitting the sleep button on top didn't do anything... it bleeped 3 times, almost sending me out of the theatre in embarrassment. I don't have to go into the settings and turn off all the notices do I? The ringer off is supposed to stop ALL sounds, per Apple's site. Anyone experience this or have a solution?
PM G5-Quad 2.5GHz | eMac G4 1.25GHz | PM G4 800MHz | PB G4 1GHz 17 | PM G4 400MH Mac OS X (10.4.5)Per the manual, the switch doesn't stop the alarm clock from going off. Which is set to marimba by default.
-
Stop all sounds as3? Help
When the game starts. I have toggle button. I can play a sound or stop sound. When i play the sound, of course its not muted so even if i go to the next page. I can reason out that the sounds will still play.
But if i press the no sound,so it means it must be muted.. on the first screen, the sound stops. But when I go the next frames and to others. The sounds are playing. The sound on the starting screen
was like
var test:Sound = new NameOfSound();
but in the next frames.. the sound is in the frame itself.. no declaring like the first screen..
and also some sounds is playing when something happens or for example if the bullet hits the target collsion..sound play..
i tried to have solution like on the first screen if for example it is muted.. ill set it to trueStop.. then on the next frames.. i would put:
if(trueStop == true){
SoundMixer.stopAll();
that way the frame sounds stopped and working.. but the sounds attach to the function when like i said if a collision happens,, the sound is still playing.. arrgghh i cant explain clearly.. i hope you understand my problem..
any ideas?if you need to stop individual sounds, assign a soundchannel to the instance returned by your play method and apply a stop method to that soundchannel.
for example:
var s1:Sound=new S1();
var sc1:SoundChannel=s1.play();
// now at any time you can use:
sc1.stop(); // to stop s1 only. -
So I made this basic game a few years ago which was in AS2 and Flash 6. Now I want to convert this game from AS2 to AS3 but I have no idea where to start. The code is approximalty 4k lines long and I don't know what to change to make it work in AS3. What do you guys suggest?
Are you using external .as files and classes or are you using frame scripts directly in the timeline? Are you used to any other object oriented programming languages? Knowing more about other languages you might know would help a lot.
AS2 very informal and specialized to Flash. It relates to pretty much no other language out there, like JavaScript seldom relates. They're c-esque but only in a very distant 3rd cousin style.
AS3 is much more OOP oriented and typed versus the less formal, error-prone loose dynamic nature of AS2. While your game would benefit greatly from the speed increases and error reduction, I think you're really swinging for the fence on this one. While some classes may resemble their AS2 counterpart and the core global functions work the same, everything else is different. Starting off trying to convert 4,000 lines of code is a little steep.
As mentioned, the resources to learn AS3 are excessive and plentiful from video training to tutorials to the API reference itself. Google has it all.
I think you really should lower your target and just try some really simple, basic things. Draw a shape, add a listener, do something basic when clicked, etc. You'll get a good idea of how different things are with the new display list rather than tearing your hair out converting your as2 game. -
Hi I am new to flash AS3. I have a program in AS2 and wants to convert it in AS3. I change the settings from File->Publish Settings. and selected "Flash player 9 and Action Script 3" and after that I am getting some error message and WARNING
WARNING: Actions on button or MovieClip instances are not supported in ActionScript 3.0. All scripts on object instances will be ignored.
WARNING: Text field variable names are not supported in ActionScript 3.0. The variable 'NumResults' used for an unnamed text field will not be exported.
Please suggest me how do I resolve this WARNINGs.You are likely to find those are just a few top level errors/warnings you'll get when you try to turn an AS2 file directly into an AS3 file. There's probably a long line of others regarding syntax and properties that will pop up once you start trying to compile the file.
AS3 does not allow code to be attached to objects like earlier versions of AS did, so you need to find each object (usually buttons) that has code attached to it, give instance names to those objects, and create that code as event listener/handler pairs.
AS3 does not allow textfields to carry vars as identifiers, so again you need to assign instance names to the textfields and use the "text" property to assign or read String values to/from them. So if you have variables that relate to textfield values, then those variables have to be equated to the text property of the textfields... var textVar = text_field.text OR text_field.text = textVar -
Stop All Sounds and goToAndPlay Label
Can someone aide me with a simple solution in AS3 to allow a
movie clip to stop a Sound Object as well as going to a label and
playing it. I'm a graphic designer trying to get a handle on AS3.
Any assistance is greatly appreciated.fiveflightsup,
> Thanks for your help.
Sure thing.
> Here's what I came up with other a little research
> ,studying your instructions and pulling out a few
> hairs. It works but question is it correct :-)
Before I continue replying, I should point out there are two
ways to
visit this forum. One way is to visit the adobe.com website
with a browser
and select Support > Forums. My guess is that you're using
this approach.
Another way is to use a news client like Thunderbird or
Outlook Express and
read Adobe's NNTP feeds. That's the way I'm using. What's the
difference?
There are many differences, but the important one is that the
browser
version lets you edit your replies, while the news client
approach does not.
That said, I have to be open to the possibility that you've
edited some
of your posts. Maybe there's something I'm just not seeing.
Bear that in
mind if my reply doesn't match up with what you've written.
You're saying you've studied my suggestions, researched this
topic, and
come up with this variation:
> var soundReq:URLRequest = new
URLRequest("flashgame_intro_extended.mp3");
> var sound:Sound = new Sound();
> var channel:SoundChannel;
>
> sound =new Sound ();
>
> sound.load(soundReq);
>
> sound.addEventListener(Event.COMPLETE, onComplete);
>
> function onComplete(event:Event):void
> {
> sound.play();
> }
While slightly different, this still doesn't make practical
use of the
SoundChannel class, so I'll spell it out this time and try to
explain a bit
more while I do.
> var soundReq:URLRequest = new
URLRequest("flashgame_intro_extended.mp3");
> var sound:Sound = new Sound();
> var channel:SoundChannel;
These lines are fine. In ActionScript, when you need an
object, you
instantiate it. The way you communicate with an object,
often, is to
declare a variable typed to that kind of object, and then set
that variable
to the object in question. That lets you refer to the object
by way of an
arbitrary variable name. You're doing exactly that:
var soundReq:URLRequest = new
URLRequest("flashgame_intro_extended.mp3");
In that line, you declare an arbitrarily named variable,
soundReq, type
it as a URLRequest object, and then set it to an instance of
the URLRequest
class. Once you do that, the variable soundReq gives you a
convenient "nick
name" or "handle" you can use to refer to that URLRequest
instance. In
fact, you use this reference a few lines later.
> sound = new Sound();
>
> sound.load(soundReq);
In this pair of lines, you don't need the first line. You
already
instantiated the Sound class earlier. No need to do it again.
The second
in this pair of lines is useful, though, because you're
putting that
previously-instantiated Sound object to work. How? By
invoking the
Sound.load() method on your object (aka instance). And this
is where you're
making use of that URLRequest instance created earlier.
> sound.addEventListener(Event.COMPLETE, onComplete);
Here, you're wiring up your Sound instance -- referred to by
the
arbitrary variable name, sound -- so that it performs the
onComplete()
function when the Event.COMPLETE event occurs (that is, when
the requested
MP3 file fully loads).
Finally ...
> function onComplete(event:Event):void
> {
> sound.play();
> }
... which is where you need to actually use your SoundChannel
instance, if
you plan to eventually stop the MP3 from playing. I did show
this in a
previous reply, but I'll repeat it here:
function onComplete(event:Event):void {
channel = sound.play();
The play() method returns a value, which happens to be a
SoundChannel
instance. You declared a SoundChannel-typed variable earlier,
named
channel, and all you're doing here is setting channel to a
SoundChannel
instance. Not just *any* SoundChannel instance, but the one
associated with
the playing of this particular sound, which is an MP3 file.
With me?
Doing what I just showed lets you stop the music later by
invoking the
SoundChannel.stop() method on your channel instance.
e.g.
// in later code ...
channel.stop();
Before you move forward, you should make sure you understand
100% what's
going on here. There shouldn't be any pulling of hair -- at
least not until
you dig into something new. ;) In order to be able to stop
sound in the
way I've been describing, you have to associate that sound
with a sound
channel.
David Stiller
Adobe Community Expert
Dev blog,
http://www.quip.net/blog/
"Luck is the residue of good design." -
How can I remove a child swf and stop all sounds when parent closes?
Hi All,
I am new to actionscript 3 and trying to learn as I go. The problem I am having is the following:
I have a carousel of images that load an external swf movie with a FLVPlayback component on it. The problem is that when the external swf unloads the sound of the FLVPlayback component continues to play. I am using a carousel component I found online to load the images and each image loads an external swf file. here is the code for it.
import com.carousel.DegreeCarousel;
import com.carousel.data.CarouselDO;
import com.carousel.data.AngleDO;
import com.carousel.data.ItemDO;
// DEFINING THE CAROUSEL OBJECT
var carouselSettings:CarouselDO = new CarouselDO();
carouselSettings.radiusX = 300;
carouselSettings.radiusY = 0;
carouselSettings.fov = 50;
carouselSettings.transitionTime = 1;
carouselSettings.ease = "easeInOutQuint";
carouselSettings.useToolTip = 0;
carouselSettings.useBlur = 1;
carouselSettings.maxBlur = 8;
carouselSettings.reflectionAlpha = 0.2;
// DEFINING ANGLES SETTINGS
var angleSettings_arr:Array = new Array();
angleSettings_arr[0] = new AngleDO({angle:0,alpha:1,scale:0.5});
angleSettings_arr[1] = new AngleDO({angle:90,alpha:1,scale:1});
angleSettings_arr[2] = new AngleDO({angle:180,alpha:1,scale:0.5});
// DEFINING THE ITEMS
var prefix = "content/thumbs/"
var galleryItems:Array = new Array();
galleryItems[0] = new ItemDO({thumb:prefix + "image_1.jpg", content:prefix + "swf1.swf", contentType: "flash"});
galleryItems[1] = new ItemDO({thumb:prefix + "image_2.jpg", content:prefix + "swf1.swf", contentType: "flash"});
galleryItems[2] = new ItemDO({thumb:prefix + "image_3.jpg", content:prefix + "swf1.swf", contentType: "flash"});
// PLACING THE CAROUSEL TO STAGE
var carousel:DegreeCarousel = new DegreeCarousel(carouselSettings,angleSettings_arr,galleryItems);
carousel.x = stage.stageWidth * .5;
carousel.y = stage.stageHeight * .5;
this.addChild(carousel);
// KEYBOARD NAVIGATION
// KEYBOARD EVENTS
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
function keyDownHandler(e:KeyboardEvent):void
// left
if(e.keyCode == 37)
carousel.left(1);
// right
if(e.keyCode == 39)
carousel.right(1);
// top
if(e.keyCode == 38)
carousel.prevCycle();
// Down
if(e.keyCode == 40)
carousel.nextCycle();
// Space
if(e.keyCode == 32)
The external movie loads fine. Then the external swf calls for a second swf containing a video. This is the code that is used to load the swf:
import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;
import flash.display.MovieClip;
import flash.events.MouseEvent;
var myVideo:URLRequest = new URLRequest("myvideo.swf");
var video:Loader = new Loader();
video.load(myVideo);
this.addChild(video);
When the carousel unloads, it unloads both movies but the sound keeps on playing.
Is there any way to stop the sound from keep playing?
Thank you very much!!
-MYou want to stop the audio from playing and also downloading more video/audio if it is still downloading when you go to a new keyframe where the video display/component or mp3 player is removed from the stage because it's keyframe ended or do not exist anymore but you still hear the audio.
Add an event listener to your video playback component that calls a function when the flash player tries to remove the video plaer from the stage that stops the netstream or at least stops/pauses the video playback.
[link removed]
//sample NetConnection and NetStream classes when the video player is removed from the stage tell the NetStream to stop playing or downloading the content with .close();
var connection:NetConnection = new NetConnection();
connection.connect(null);
var stream:NetStream = new NetStream(connection);
addEventListener(Event.REMOVED_FROM_STAGE, videoRemovedFromStage);
function videoRemovedFromStage(e:Event){
stream.close(); -
My iphone 5 stopped all sounds cant get it to ring or any sounds at all
MY I 5 PHONE STOPPED RINGING ALL SOUNDS ARE GONE , I FLIP THE MUTE SWITCH AND TURN PHONE OFF I TRIED EVERY THING HOW CAN I GET SOUND BACK ?
Make sure the Side Switch is in the correct "up" position, meaning pushed closer toward the face of the phone (the side with the screen), then try pushing your volume buttons see if the ringer volume changes, if that doesnt work go into your Settings>Sounds and check all of those settings
-
Is there a way to block an IMAC from making or playing any sound. I am trying to block other users not just the mute button.
Well to stop all the sound (but not the start up tone) you can get an old headphone and connected it on the rear of the iMac audio output automatically all the sound from any user will go to the headphones (a old iPod headphone) and if it is broken no sound at all, if you hide the headphones on the rear of the iMac with the other cables a regular user will not find out about this trick easily.....normally they will look for the volume control or some kind of control on the keyboard or front or the side of the iMac.
Good luck -
Pls. help on AS2 to AS3 convertion for #initclip and Object.registerClass
Hi Friends,
I have converted most of the as2 code to as3 but I am stuck with the below kind of codes where the code looks like #initclip and some number next to it and inside it Object.registerClass("some reference", some reference); and ending with #endinitclip
Below is an example of what I am talking about.
#initclip 45
Object.registerClass("Border", mx.skins.Border);
#endinitclip
Thanks in advance.
With Regards,
Sagar S. RanpiseSOLVED:
Hey Friends,
I was able to solve the issue. Since no one was able to give me answer, I think most of you might not be knowing the solution.
Hence posting it below. All I have done is Added Event listener to instance name of movieclip and in the function I have imported the class the object.registerclass was refering and below import I created a new scrollbar instance and added that to my movieclip which solved the issue.
Let me know what you think?
boundingBox_mc.addEventListener(Event.ADDED_TO_STAGE, scrollbarFunction);
function scrollbarFunction(e:Event):void
// Import the class.
import mx.controls.UIScrollBar;
// Create the scrollbar
var scroller:UIScrollBar = new UIScrollBar();
boundingBox_mc.addChild(scroller);
//Object.registerClass("UIScrollBar", mx.controls.UIScrollBar);
Maybe you are looking for
-
Increase font size in Windows 7 Photoshop Elements 11?
I'd have thought (since this has been a problem since 9 and that HD displays are fairly common now) it would have been addressed. I still can't find a way to increase the font size in PE 11, though. Am I missing something? It seems the menu fonts hav
-
How to count the no of digits entered in the NumericField & print the same
Hi! How to count the no of digits entered in the Numberic Field and print the content of Numberic Field. Thanks.
-
I just recently have been trying to use dictation on my iPad for the past two weeks. It's been working fine up until recently. Everything was working every single type of function from capitalization two parentheses in quotations. Now however capital
-
Hello, We are trying to connect to Domain, Domain name is set up on the server. We ping the IP and its working, but when we try to join the domain the following errors pop up An Active Directory Domain Controller (AD DC) for the domain "proximity" co
-
Hi Everyone I was trying to move a phone from one DP to another and when I move the phone and went to save the changes it gave me this error below and I wanted to know what would cause this and how would I go about fixing this problem. The attempted