I need something very simple as a Flash application.
Just a single button that will call an action script. That action script will call
private var m_MicCnx:NetConnection; //connection over the server
private var m_MicStream:NetStream; //Audio Output
private var m_Microphone:Microphone; //micro, attach with m_MicStream's audio content
m_MicCnx =new NetConnection();
m_MicCnx.client = this;
m_MicCnx.addEventListener(NetStatusEvent.NET_STATUS,HandlerMicCnxStatus);
m_MicCnx.connect(m_strMicUrl);
m_MicStream.publish ("mp3:myStream", "live");
m_Microphone=Microphone.getMicrophone();
m_Microphone.gain=85;
m_Microphone.rate=11;
m_Microphone.setSilenceLevel(15,2000);
private function HandlerMicCnxStatus(e:NetStatusEvent):void
{
var isConnected:Boolean; //tells whether the connection has succeded
isConnected=e.info.code=="NetConnection.Connect.Success";
if (isConnected)
{
m_MicStream=new NetStream(m_MicCnx);
m_MicStream.attachAudio (m_Microphone);
}
}
I think this is the most simple setup I can get that will publish a microphone to a RTMP stream. This is an attempt to shave down a larger product. This demo will help a third party create a RTMP Stream Reader for mp3.
My question is : How do I move from this snippet of code to a flash application? Most tutorials I’ve found so far were either about using menus or creating very complex animations. I just need a single button that will call this, or maybe an auto-load.
Where can I get a straight-forward tutorial? I understand there will be a boatload of clicking everywhere, but if you could explain it here it would be awesome.
I’ll explain as if it your first time working with flash.
Like any other language you have some sort of bootstrap file and a main function. In Flash you have something called a document class. The document class gets called when the application is started. Read more about that here.
To use a document class you specify it in the properties of your .fla file, like so:
This tells flash that it should use the class
Mainin the fileMain.asas the document class.Here’s what the document class looks like that I am using in the example:
The
Mainclass gets instantiated and the constructor is called, and thus tracing “Application started” to the console. The document must inherit a class which is a subclass ofDisplayObject. If you want to be able to use frame operations useMovieClipand if you are not going to use any frame operations in your document class useSprite.Next step is to move your code in to an separate class that you can call from your document class. So you will get a structure of your project like this:
Your
MicrophoneRTMP.aswill look something like this:Then you just need to alter your
Main.asto import and call your class:Note:
Now you will be able to compile your project and start debugging your
MicrophoneRTMPclass, it contains some errors you need to look over.Concept in my example you can read more about: