Recording using Flex/Flash - actionscript-3

I know that we can not record/Access anything out of flash player, because of it's security sandbox.
Instead We can record the video while streaming it to server.
like
netStream.publish("YourFileName.flv","record");
But in recorde file, I will get only a video file Published by webcam to server and i want to record entire session.
Is there any way to record it locally, or Can i record the window ??
p.s. : I am not trying to access anything outside of flash player.
Thanks in advance...

ok, so you can record the entire contents of the swf like this:
first, create a container object (anything that extends DisplayObject which implements IBitmapDrawable) then place everything that you want to capture (video view and everything else in your "session") then using an ENTER_FRAME event or Timer (preferable to control capture fps), draw the container to a BitmapData using BitmapData.draw(container). Pass that BitmapData to the FLV encode library found here using it's addFrame() method (docs and examples come with that library... super easy) and that's it! When you are done, you will have an flv video containing a frame by frame "screen capture" of what was going on in your swf! Just make sure EVERYTHING is in the container! That lib also accepts captured audio too if you want.
private function startCapturing():void{
flvEncoder.start(); // see the libs docs and examples
var timer:Timer = new Timer(1000/15); //capture at 15 fps
timer.addEventListener(TimerEvent.Timer, onTimer);
timer.start();
}
private function onTimer(event:TimerEvent):void{
var screenCap:BitmapData = new BitmapData(container.width, container.height);
screenCap.draw(container);
flvEncoder.addFrame(screenCap); // see the libs docs and examples
}

Related

How to properly add "Replay" functionality to a self-preloaded Flash movie?

I made a Flash project in FlashDevelop to create an Ad.
The Preloader is setup by making use of the Additional Compiler argument:
-frame=NameOfLabel,NameOfMainClass
My main class is simply called "Main", at the top / default package level.
So frame #1, being the Preloader portion of the SWF, has:
Very few bitmaps, vector-graphics and text (to stay under 50kb);
A YouTube video player in the center (does not count in the filesize limit);
The frame #2 has everything else (the Main class basically embeds all it's dependencies). This includes:
Assets from precompiled SWF (Bitmaps, Symbols, Fonts, XML data);
All classes imported (this is recursive for every classes importing other classes);
Now my big problem is, my client requested the "replay" functionality long after I've completed 99.9% of the project.
I have the project more-or-less broken into different states (Intro, Ready, SlideMenu, etc.), but I'm not sure how I can easily reset the Flash movie back to the very beginning (where it was preloading and showing the YouTube video).
The easy solution would be to simply call an ExternalInterface JavaScript method that would refresh the Flash container, BUT I don't think I have control over what's going on the HTML / JavaScript side.
Is there an easy way to invoke a replay function from AS3?
Would not simply going back to frame 1 do the trick ?
The following seems to do the trick!
private function onReplayClick(e:MouseEvent):void {
var theStage:Stage = this.stage; //Temporarly store the stage.
//Kill any animations happening:
TweenMax.killAll(); //3rd party, may not be applicable for you :P
//Remove ALL containers / child DisplayObjects
SpriteUtils.recursiveRemove(theStage); //custom-made
// (this object is no longer attached to the stage at this point)
//Nullify any Singleton / Static variables:
Main.INST = null;
// Load the 'bytes' of the current SWF in a new Loader, then...
// add it to the stage
var swf:Loader = new Loader();
swf.loadBytes( theStage.loaderInfo.bytes );
theStage.addChild( swf );
}
By doing a deep recursive cleanup of the DisplayObjects, and any static variables (like Singleton instances), it leaves you with a blank stage.
After that, you can instantiate a new Loader that will load the SWF itself via the current LoaderInfo's bytes property.
Add the Loader to the Stage, and you're up and running again!

How to play two swf files in as3

hai i want play two swf files in my action script project.In this two files one swf file works on the detection face in front of the system.Other swf plays the flv file.when face is detected player must be stooped if not player must be plays the flv file.
I know how to load the swf file but i cant handle the functionality regarding starting and stoping player.
the snippet of code shows how can i load external swf file .and i will explain each line of code in comments
public function videos(view:Sprite)
{
this.box = view;//IT GETS Sprite object from other class because of need to display the player also.
request = new URLRequest("Untitled-1.swf");
currentSWF=new MovieClip();
loader= new Loader();
loader.load(request);
box.addChild(loader);
currentSWF = MovieClip(loader.content);
loader.addEventListener(Event.COMPLETE,loadComplete);
//addChild(loader);
currentSWF.gotoAndPlay(1);//when i put this line of code in comments it plays the external swf also.
}
I hope u understand my doubt .can any one explain how to handle my things .i am new to this action script.please help me
Loaded files automatically play, unless you tell them explicitely not to. You’ll have to listen to the Event.INIT event, and stop the movie there:
loader.AddEventListener(Event.INIT, initLoader);
function initLoader (event:Event)
{
MovieClip(event.currentTarget.content).stop();
}
This will stop the movie before it is attached to the stage, and before it starts playing—so it won’t do that unless you start it again.
Note that you shouldn’t access loader.content in any way before the INIT or COMPLETE events, as it’s very likely that the content isn’t loaded then. As such you should put all your manipulating actions into the COMPLETE event:
box.addChild(loader);
loader.addEventListener(Event.COMPLETE, loadComplete);
function loadComplete (event:Event)
{
// Now it’s safe to access the `content` member:
currentSWF = MovieClip(loader.content);
// Of course this one would play the movie again, so you probably want
// to call that later on a button click or something.
currentSWF.gotoAndPlay(1);
}

How do I create Video object statically on stage?

Needless to say I am a beginner in Flash. I want to add Video Object to my stage. How do I do that? In my components window the closes component I see is FLVPlayback. I want to show my webcam. Well my stage has an instance of FLVPlayback and I named it video.
I then try to show webcam using:
cam = Camera.getCamera();
if(cam != null)
{
cam.setQuality(144000, 85);
cam.setMode(320, 240, 15);
cam.setKeyFrameInterval(60);
video.attachCamera(cam);
}
in a button click but I get this error:
1061: Call to a possibly undefined method attachCamera through a reference with static type fl.video:FLVPlayback.
Note: All the examples on the web dynamically create Video. It works that way but how I want to create my video object on stage only and position it properly. I don't want to create it at runtime using new.
Based on your error message, "video" is an instance of FLVPlayback, which, according to the documentation, wraps a VideoPlayer object. It looks like FLVPlayback provides most of the same methods as VideoPlayer, which is why you got the two confused, but one method FLVPlayback does not provide is attachCamera().
Try this instead:
video.getVideoPlayer(video.activeVideoPlayerIndex).attachCamera(cam);
Remove the FLVPlayback object from stage and get rid of it completly so it doesnt block the name video anymore.
Then change your code like this:
import flash.media.video; //here you get the right video class from flash library
var video = new Video(); // this will work after the import is done
cam = Camera.getCamera();
if(cam != null)
{
cam.setQuality(144000, 85);
cam.setMode(320, 240, 15);
cam.setKeyFrameInterval(60);
video.attachCamera(cam);
addChild(video) // brings video object to stage so its visible
}
You took the wrong component, but you want to create an Video instance first and then attach the cam to it... mostly right what you did

Audio of a specific video swf doesn't stop when I load another URLRequest

I am trying to stop the audio of the video swf and I can't get it to stop. Here is my code for loading the file:
var myLoader:Loader= new Loader();
myLoader.x=420;
myLoader.y=200;
// boolean variable set for use below in our function
var screenCheck:Boolean = false;
//These three linces keep stafe elements the same size, so they don't distort
var swfStage:Stage = this.stage;
video_btn.addEventListener(MouseEvent.CLICK,contentvideo);
function contentvideo (event:MouseEvent):void{
myLoader.load(new URLRequest("prevideo.swf"));
addChild(myLoader);
movie_btn.stop();
movie_btn.visible=false;
}
Now I have other functions that load different URLRequest and when they are loading, the audio keeps playing. Do I have to add a line of code to them? I also have an MP3 player and tried SoundMixer.stopAll(). I still need the mp3 player to keep playing.
I'm not familiar with what you're doing but just looking at the code and given the problem you're experiencing I wonder if that
addChild(myLoader);
has anything to do with it. It seems like the kind of thing that could easily create multiple child objects which is why you continue to experience the sound play back. Is there a removeChild[0] option or something?
A shot in the dark I know but I thought I'd offer the possibility anyway.

How does one stop a SWF Movie dynamically loaded using the Loader class using ActionScript 3.0?

MovieClip(_loader.content).stop();
this.removeChild(_loader);
_loader.unload();
_loader = null;
I've been trying that, but it doesn't stop the movie. The movie has an embedded voiceover
and that keeps running. thank you.
Flash 10 introduced unloadAndStop(); (_loader.unloadAndStop() if it's named _loader like in your example) and if you are using Flash 10 then you should use this.
But the original idea of what Adobe intended in AS3 for Flash 9 was that the loaded in swf would be self reliant, able to detect when it was removed and stop the sound from within itself. Use this inside the swf that is being loaded in, so that it can detect when it is removed from the stage, and therefore shut down it's own sound:
addEventListener(Event.REMOVED_FROM_STAGE, swfWasRemoved);
function swfWasRemoved(event: Event) : void
{
// inside this function shut down the sound that is inside the swf
}
If the only remaining thing that is playing is the sound, use SoundMixer.stopAll() to stop that as well.
Make sure the embedded voice over is set to stream. If its on event, it will just keep playing until it's done regardless of the playhead of the swf.