Music is not Playing - actionscript-3

Hi Iam trying to play sound i have been already inserted the media to library but it was not playing but here trace working...
Please Someone help me to find it out Thank you...
import flash.net.URLRequest;
import flash.media.Sound;
import flash.events.MouseEvent;
stop();
var Myrequest:URLRequest = new URLRequest("hello.wav");
var mySound:Sound = new Sound();
mySound.load(Myrequest);
musicBtn.addEventListener(MouseEvent.CLICK, OnPlay);
function OnPlay(e:MouseEvent)
{
mySound.play();
trace("ok");
}

Related

How do I stop sound using AS3)

my sounds in code called sound1 , sound2 my sounds in class called sounda , soundb I hope find answers to fix my problem`
import flash.events.Event;
import flash.media.Sound;
import flash.media.SoundChannel;
stop();
var sound1:sounda = new sounda();
var sound2:soundb = new soundb();
cbox.addItem( { label: "chose"} )
cbox.addItem( { label: "first"} )
cbox.addItem( { label: "sec"} )
cbox.addEventListener(Event.CHANGE,plays);
function plays(e:Event):void
{
if (cbox.selectedItem.label == "first")
{
sound1.play();
//not working
sound2.stop();
}
if (cbox.selectedItem.label == "sec")
{
sound2.play();
//not working
sound1.stop();
}
}
//when I play sound1 then when I play sound2 .. sound1 still playing
to stop all sounds from playing
import flash.media.SoundMixer;
SoundMixer.stopAll();
to stop a single sound, you must using SoundChannel
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLLoader;
var mySound:Sound = new Sound();
var myChannel:SoundChannel = new SoundChannel();
mySound.load(new URLRequest("myFavSong.mp3"));
myChannel = mySound.play();
// ...
myChannel.stop();

How to save input text as bitmap in as3? Can anyone please tell me why this code is not working?

1.How to save input text as bitmap in as3? Can anyone please tell me why this code is not working?
Some class files are imported here
import flash.text.TextField;
import flash.display.MovieClip;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.PNGEncoderOptions;
import flash.utils.ByteArray;
import flash.net.FileReference;
import com.adobe.images.JPGEncoder;
import flash.events.MouseEvent;
import fl.motion.MotionEvent;
Code starts here
var bitmapdata: BitmapData = new BitmapData(200, 200);
bitmapdata.draw(txt);
var xmv: MovieClip = new MovieClip();
xmv.graphics.beginBitmapFill(bitmapdata);
xmv.graphics.drawRect(0, 0, 200, 300);
xmv.graphics.endFill();
var jpgEncoder: JPGEncoder = new JPGEncoder(100);
save.addEventListener(MouseEvent.CLICK, click)
function click(e:MouseEvent)
{
var imgByteData: ByteArray = jpgEncoder.encode(bitmapdata);
var file = new FileReference();
file.save(imgByteData, "Image.jpg");
}
Thank you all for your kind responses! I appreciate it a lot. There hasn't really been any issue with the code. After I replaced the 'txt' input box with a new one, it functioned properly. So the problem might have been with some of the changes I've made unknowingly to the input box. I even customized the code for user input to be displayed as bitmap. Thanx again!

Stopping a sound in AS3

I'm making a little interactive ad for an album. It has 4 draggable song titles, that when dropped on a target, starts the song. Trying to figure out how to stop the song that's playing when a new song is started. Here's my code:
package {
import flash.display.*;
import flash.events.*;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;
public class Deftones extends MovieClip{
function Deftones() {
swerve1.addEventListener(MouseEvent.MOUSE_DOWN, dragStartS);
swerve1.addEventListener(MouseEvent.MOUSE_UP, dragEndS);
polt1.addEventListener(MouseEvent.MOUSE_DOWN, dragStartS);
polt1.addEventListener(MouseEvent.MOUSE_UP, dragEndS);
rd1.addEventListener(MouseEvent.MOUSE_DOWN, dragStartS);
rd1.addEventListener(MouseEvent.MOUSE_UP, dragEndS);
gauze1.addEventListener(MouseEvent.MOUSE_DOWN, dragStartS);
gauze1.addEventListener(MouseEvent.MOUSE_UP, dragEndS);
var sound1:Sound= new Sound();
var sound2:Sound= new Sound();
var sound3:Sound= new Sound();
var sound4:Sound= new Sound();
sound1.load(new URLRequest("music/Swerve_City.mp3"));
sound2.load(new URLRequest("music/Poltergeist.mp3"));
sound3.load(new URLRequest("music/Romantic_Dreams.mp3"));
sound4.load(new URLRequest("music/Gauze.mp3"));
var channel:SoundChannel= new SoundChannel();
function dragStartS(e:MouseEvent){
e.currentTarget.startDrag();
}
function dragEndS(e:MouseEvent){
e.currentTarget.stopDrag();
if (swerve1.hitTestObject(speaker1)){
channel.stop();
sound1.play(0);
}
else if (polt1.hitTestObject(speaker1)){
channel.stop();
sound2.play(0);
}
else if (rd1.hitTestObject(speaker1)){
channel.stop();
sound3.play(0);
}
else if (gauze1.hitTestObject(speaker1)){
channel.stop();
sound4.play(0);
}
}
}
}
Any help would me much appreciated.
You can use SoundMixer.stopAll()
Stops all sounds currently playing.
You can use SoundChannel class for this, look in this link (Section 4 - Stopping a Sound)

How to remove stream video in next scene AS3

I am making a project with a video in a scene, but when I go to the next scene the video keeps appearing. How can I remove it.
My code so far is:
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.media.Video;
import flash.events.MouseEvent;
var videoConnection:NetConnection = new NetConnection();
videoConnection.connect(null);
var videoStream:NetStream = new NetStream(videoConnection);
videoStream.play("short_jump.flv");
var metaListener:Object = new Object();
metaListener.onMetaData = onMetaData;
videoStream.client = metaListener;
var video:Video = new Video();
video.attachNetStream(videoStream);
stage.addChild(video);
video.x=200;
function onMetaData(data:Object):void
{
play_btn.addEventListener(MouseEvent.CLICK, playMovie);
stop_btn.addEventListener(MouseEvent.CLICK, stopMovie);
}
function playMovie(event:MouseEvent):void
{
videoStream.play("short_jump.flv");
}
function stopMovie(event:MouseEvent):void
{
videoStream.pause();
}
Thanks for your support!
video.attachCamera( null ) stops audio and video but the last frame remains in the video. you should just video.visible = false afterwards so you don't see that frame. there's a bug where clear() doesn't do what it should.

Drawing on Live Video in Flex - Snapshot issue

I am working on a project, where I have to make an annotation video player!
Basically, I followed this tutorial[1] where the author presents how to draw(in this case just a rectangle) on the own web camera, using Flex.
Everything went great, but now I want to add a listener to get a snapshot of the image(what I draw + the web camera image) and then save it on my computer.
I have created the listener, but the problem is that this listener saves only the image from the web camera without my drawing(even though I added that draw to the camera).
private function save():void {
var bitmapData:BitmapData = new BitmapData(videoDisplay.width,videoDisplay.height);
bitmapData.draw(videoDisplay);
var ba:ByteArray = (new PNGEncoder()).encode(bitmapData);
(new FileReference()).save(ba, "doodle.png");
}
I don't have experience at all with Flex/Flash so maybe I did smth wrong.
Can you please help me?
[1]http://narinderkumar.wordpress.com/2012/02/16/drawing-on-live-video-in-flex/
this example works fine - i dont see the problem in that codesnippet of yours but maybe you are just drawing vis graphics on the video, in thatcase the graphics layer is behind the camera... hope hat helps ;)
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.media.Camera;
import flash.media.Video;
public class cameratest extends Sprite
{
private var holder:Sprite;
private var layover:Sprite;
private var display:Sprite;
public function cameratest()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
var cam:Camera = Camera.getCamera();
var video:Video =new Video(cam.width, cam.height);
video.attachCamera(cam);
//holder hollds the video and on top the layover to draw on
holder = new Sprite();
stage.addChild(holder);
holder.addChild(video);
//layover to draw on
layover = new Sprite();
holder.addChild(layover);
//will show the snapshot
display = new Sprite();
display.x= 350;
stage.addChild(display);
//listener for onclick do snapshot
stage.addEventListener(MouseEvent.CLICK, drawAndSave);
}
private function drawAndSave(E:Event=null):void{
layover.graphics.beginFill(0xff0000,1);
layover.graphics.drawCircle(10,10,10);
var bmd:BitmapData=new BitmapData(holder.width,holder.height);
bmd.draw(holder);
var bmp:Bitmap = new Bitmap(bmd,'auto',true);
display.addChild(bmp);
}
}
}