| By Stefan Richter | Article Rating: |
|
| October 12, 2005 03:00 PM EDT | Reads: |
26,421 |
This code initiates the following actions. First it disables the startstop_pb button instance. You will enable it again after a successful connection to the server has been established.
Next comes the onRelease function for the connect_pb button instance. This code emulates a toggle state so that the button can be used to both connect and disconnect based on the current label. At the same time the code outputs status messages into the status_txt field on the Stage to help you visualize what's happening behind the scenes. The following code will disable the broadcast button when you close the connection to your server:
startstop_pb.enabled = false
The actual connection to Flash Communication Server is triggered by this line:
nc.connect(rtmp_txt.text);
As you may have noticed, this code grabs whatever text is currently displayed in the rtmp_txt text input field and passes it as a parameter to the NetConnection object's connect method. This enables you to connect to different servers (or applications) without having to hard code connection strings into the SWF file. If it makes live easier for you, then you can easily prefill the value for this input field inside the Flash authoring environment: Just highlight the component on the Stage, bring up the Properties panel and fill in the text value. Note that you must use the complete rtmp string to your server, including rtmp:/ or rtmp://.
At the bottom of this code block is the onStatus function for your NetConnection object. This function listens for a NetConnection.Connect.Success message and, after receiving one, enables the startstop_pb button instance as you are now ready to create a NetStream function and start broadcasting.
The last code block disables the broadcast button and resets its label in case you get disconnected, either because you have chosen to or maybe because the connection has dropped for unknown reasons. It also cleans up the video object on the Stage by issuing the following:
myvid.attachVideo(null);
myvid.clear();
Step 4: Create a NetStream Object and Publish the Stream
You will create a NetStream object after the startstop_pb button is clicked. The name for the stream will be based on whatever value the streamname_txt text field holds.
Add the following code underneath the existing code in frame 1:
This code is fairly self-explanatory:
startstop_pb.onRelease = function(){
if (this.label == "Start Broadcast"){
status_txt.text += "Starting broadcast" + newline;
this.label = "Stop Broadcast";
ns = new NetStream(nc);
ns.onStatus = function(info) {
status_txt.text += "NS.onStatus> info.code: " + info.code + newline;
}
mycam = Camera.get();
mycam.setQuality(25600, 0);
mymic = Microphone.get();
mymic.setRate(11);
ns.attachVideo(mycam);
ns.attachAudio(mymic);
myvid.attachVideo(mycam);
ns.publish(streamname_txt.text, "live");
} else {
status_txt.text += "Stopping broadcast" + newline;
this.label = "Start Broadcast";
myvid.attachVideo(null);
myvid.clear();
ns.close();
}
}
1. First (if the current button label is Start Broadcast) it creates a new NetStream object on our existing NetConnection object (ns = new NetStream(nc);).
2. It then adds an onStatus handler (ns.onStatus = function(info)[...]), which enables you to see trace output inside the status_txt text area.
3. Next, it grabs a reference to the default camera that's installed mycam = Camera.get(); and calls the setQuality method with a parameter of 25600 bytes and 0 (best possible) image quality at that given bandwidth mycam.setQuality(25600, 0);. Feel free to adjust these settings as you see fit.
4. Next comes the equivalent action for the default microphone:
5. mymic = Microphone.get();
mymic.setRate(11);
6. To be able to send audio and video across the Internet, you must attach both sources to the NetStream object:
7. ns.attachVideo(mycam); ns.attachAudio(mymic);
8. Now you need to attach the local camera feed to the video object on the Stage. This will enable you to see the feed that you will be broadcasting. myvid.attachVideo(mycam);
9. By calling ns.publish(streamname_txt.text, "live") you start the broadcast. You can omit the parameter "live" if you want, because the publish method would actually default to a live stream. However, using this parameter makes matters a little clearer I think.
Published October 12, 2005 Reads 26,421
Copyright © 2005 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Stefan Richter
Stefan Richter is a Certified Flash Developer and Team Macromedia member who has been involved with Flash Communication Server since its early days. As VP of Application Development and cofounder of POPview, he has developed a variety of Rich Internet Applications using Flash Communication Server, Flash MX 2004 and Coldfusion. You can find more of Stefan's articles at www.flashcomguru.com.
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Adobe Unveils LiveCycle Enterprise Suite 2 for Deployment in the Cloud
- Adobe Flex Developer Earns $100K in New York City
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Ph.D. in Twitter Anyone?
- Eolas Sues the Internet
- Adobe LiveCycle Enterprise Suite 2 for Cloud Computing
- Adobe Betas Target RIAs and Cloud Computing
- Special Report on the Emerging Cloud Computing Trend
- Adobe Cans Another 9% of its Workforce
- My Thoughts on Ulitzer
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Ulitzer Live! New Media Conference & Expo
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Eval JavaScript in a Global Context
- Fig Leaf Software to Exhibit at Government IT Conference & Expo
- Cloud Executives Feature on Cloud Computing Expo Power Panel
- Software Flexibility in the Cloud - Part 4 of 5
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Is Microsoft as Free as Open Source?
- Adobe Reader Sued
- Adobe Unveils LiveCycle Enterprise Suite 2 for Deployment in the Cloud
- Where Are RIA Technologies Headed in 2008?
- Cover Story: How to Increase the Frame Rates of Your Flash Movies
- AJAX World RIA Conference & Expo Kicks Off in New York City
- Your First Adobe Flex Application with a ColdFusion Backend
- Adobe Flex 2: Advanced DataGrid
- i-Technology Blog: Death-Knell For "Rich Media? Hardly!
- Adobe/Macromedia - Microsoft, Look Out!
- How To Create a Photo Slide Show ...
- Adobe Flex Interface Customization - Themes, Styles, Skins
- Personal Branding Checklist
- Has the Technology Bounceback Begun?
- "Real-World Flex" by Adobe's Christophe Coenraets



































