How to remove stream video in next scene AS3 - actionscript-3

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.

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 successfully unload a swf, and go to parent swf, after pressing the exit button

Using a code snippet in as3 flash, but struggling for it to actually work:
I would like to unload the child SWF (which is a video) and go back into the parent SWF (a video selection page). Tried so many different ways and need a quick and easy solution. Thanks.
Below does not seem to work...
exit_btn.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF);
import fl.display.ProLoader;
var fl_ProLoader:ProLoader;
//This variable keeps track of whether you want to load or unload the SWF
var fl_ToLoad:Boolean = true;
function fl_ClickToLoadUnloadSWF(event:MouseEvent):void
{
fl_ProLoader.unload();
removeChild(fl_ProLoader);
fl_ProLoader = null;
}
I use this code it's tested
import flash.filesystem.*;
import flash.events.MouseEvent;
import flash.net.*;
import flash.events.*;
var _file: File;
_file = File.documentsDirectory.resolvePath("./Directory to swf file/mySwf.swf");
if (_file.exists) {
trace("SWF loading ...........");
displayingSWF(_file.nativePath)
} else {
trace("the file doesn't exit");
}
//////////////// DIsplay the SWF story file //////////////////
var mLoader: Loader ;
function displayingSWF(lnk) {
var inFileStream: FileStream = new FileStream();
inFileStream.open(_file, FileMode.READ);
var swfBytes: ByteArray = new ByteArray();
inFileStream.readBytes(swfBytes);
inFileStream.close();
mLoader = new Loader();
var loaderContext: LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
loaderContext.allowCodeImport = true;
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onSwfLoadComplete);
mLoader.loadBytes(swfBytes, loaderContext);
}
function onSwfLoadComplete(e: Event): void {
mLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onSwfLoadComplete);
addChild(mLoader);
}
exit_btn.addEventListener(MouseEvent.CLICK, dimising);
function dimising(e: MouseEvent): void {
mLoader.unloadAndStop();
removeChild(mLoader);
}

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)

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);
}
}
}

Converting AS3 to AS2

I have this problem. Have a banner which is code with AS3, and our system only displays banners up to Flash Player 9. But Flash Player 9 does not support AS3 . So is there a way to do it on the easy way? Or I have to rewrite it on AS2 ? Here is the code.
import flash.events.Event;
import flash.net.URLRequest;
import flash.events.MouseEvent;
import flash.media.SoundTransform;
import flash.media.SoundMixer;
cierre.gotoAndStop(1);
SoundMixer.soundTransform = new SoundTransform(0);
video_player.autoPlay = true;
video_player.source = "video_500x374.f4v";
video_player.addEventListener(Event.COMPLETE, finVideo);
stop();
b2_btn.buttonMode = true;
buttonclose.addEventListener(MouseEvent.CLICK,buttoncl);
function buttoncl(e:Event):void{
video_player.stop();
this.gotoAndStop(1);
}
var paramList:Object = this.root.loaderInfo.parameters;
b2_btn.addEventListener(MouseEvent.CLICK, openURL);
function openURL(evtObj:MouseEvent):void {
var request:URLRequest = new URLRequest(paramList["clickTag"]);
navigateToURL(request, "_blank");
}
function aBanner1(e:Event):void{
video_player.stop();
this.gotoAndStop(1);
}
function finVideo(e:Event):void{
video_player.stop();
cierre.play();
}
function setMute(vol) {
var sTransform:SoundTransform = new SoundTransform (0,1);
sTransform.volume = vol;
SoundMixer.soundTransform = sTransform;
}
var Mute:Boolean = false;
mutebutton.addEventListener (MouseEvent.CLICK,toggleMuteBtn);
function toggleMuteBtn (event:Event) {
if(Mute) {
Mute = false;
setMute(0);
}else{
Mute = true;
setMute(1);
}
}
You need to use the AS2 FLV Playback component. You should start with a clean new AS2 fla and start copying everything over except the components stuff.