Multicast Streaming in Flash Player 10.1 revisited

Yesterday a student from my class ask me to help him solve a problem that was getting when testing Tom Krcha’s example files of his Multicast Streaming tutorial. Here’s the fix.

Yesterday a student from my class ask me to help him solve a problem that was getting when testing Tom Krcha’s example files of his Multicast Streaming tutorial, the files he was using were the same included in Tom’s tutorial except for the Stratus Developer Key so after looking at the video tutorial included and testing the examples files You’ll get this error:

?View Code ACTIONSCRIPT3
1
2
3
4
5
Error: Error #2154: The NetStream Object is invalid.  This may be due to a failed NetConnection.
	at flash.net::NetStream/invoke()
	at flash.net::NetStream/attachCamera()
	at Broadcaster/setupStream()[C:\Users\Dave\Adobe Flash Builder 4\Broadcaster\src\Broadcaster.mxml:67]
	at Broadcaster/netStatus()[C:\Users\Dave\Adobe Flash Builder 4\Broadcaster\src\Broadcaster.mxml:50]

The error is pretty descriptive and what is saying is that was the NetStream was not getting the Camera signal or received a null value when trying to attach it.

The reason that this was happening is because in the NetStatusEvent Listener inside the switch statement we are using the event.info.code = “NetConnection.Connect.Success”; both for the Connection and the Stream

?View Code ACTIONSCRIPT3
1
2
netConnection.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
stream.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
?View Code ACTIONSCRIPT3
1
2
3
4
5
6
7
8
9
10
private function netStatus(event:NetStatusEvent):void{
	   writeText(event.info.code);
 
	   switch(event.info.code){
	            case "NetConnection.Connect.Success":
		    setupStream();
                    break;
		}
 
}

And on the setupStream() function we are trying to attach the camera and thats what throws the error cause we are using the “NetConnection.Connect.Success” to call this function.

?View Code ACTIONSCRIPT3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
private function setupStream():void
{
      var groupspec:GroupSpecifier = new GroupSpecifier("myGroup/multicastOne");
      groupspec.serverChannelEnabled = true;
      groupspec.multicastEnabled = true;
 
      stream = new NetStream(netConnection,groupspec.groupspecWithAuthorizations());
      stream.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
 
       var cam:Camera = Camera.getCamera();
 
       stream.attachCamera(cam);
       stream.publish("multicast");
 
	video.attachCamera(cam);
}

The fix is pretty straightforward all You have to do is include a case for the event.info.code: “NetStream.Connect.Success” and thats where we attach the camera to our stream.

?View Code ACTIONSCRIPT3
1
2
3
4
5
6
7
8
9
10
11
switch(event.info.code){
	case "NetConnection.Connect.Success":
	        setupStream();
	break;
	case "NetStream.Connect.Success":
	        var cam:Camera = Camera.getCamera();
	        stream.attachCamera(cam);
	        stream.publish("multicast");
	        video.attachCamera(cam);
	break;
}

And our setupStream() function will only define the GroupSpecifier and the NetStream:

?View Code ACTIONSCRIPT3
1
2
3
4
5
6
7
8
private function setupStream():void{	
	var groupspec:GroupSpecifier = new GroupSpecifier("myGroup/multicastOne");
	groupspec.serverChannelEnabled = true;
	groupspec.multicastEnabled = true;
 
	stream = new NetStream(netConnection,groupspec.groupspecWithAuthorizations());
	stream.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
}

Attaching camera / microphone after NetStream is connected, prevents you from following:

?View Code ACTIONSCRIPT3
1
Error #2154: The NetStream Object is invalid. This may be due to a failed NetConnection.

Click here to open my example, or here to download the flex project.

You should see Your Broadcaster and your Receiver getting along just fine.

Flash Builder 4 & Flex 4 Framework have been released

Adobe Flash Builder 4 has been released and with it the Flex 4 framework some of the features listed below:
Powerful coding tools ENHANCED
Develop using a powerful Eclipse™ based IDE that includes editors for MXML, the ActionScript® language, and CSS, as well as syntax coloring, statement completion, code collapse, interactive step-through debugging, and automatic generation of common code.
Rich visual layout ENHANCED
Visually design and preview user interface layout, appearance, and behavior using a rich library of built-in components. Extend the built-in Flex framework components or create new ones as needed. Import functional application UI created using the Adobe Flash Catalyst™ interaction design tool.
Data-centric development NEW
Introspect Java™, PHP, Adobe ColdFusion®, REST, and SOAP services to display methods and properties in the new Data/Service Explorer. Bind methods to UI components using a simple drag-and-drop approach.
Interactive data visualization ENHANCED
Create data dashboards and interactive data analysis by simply dragging and dropping a chart type and linking it to a data source using the Flex Charting library. Use the powerful Advanced Datagrid to enable users to explore complex data.
Skinning and styling ENHANCED
Customize the appearance of an application using CSS and graphical property editors. Quickly set the most commonly used properties and preview the results in Design View. Browse available themes and apply them to your project using the new Theme Browser.
Integration with Adobe Creative Suite design toolsENHANCED
Import design assets created using Adobe Flash Professional, Illustrator®, Photoshop®, or Fireworks® software, or import a complete application user interface created using Flash Catalyst. A new workflow between Flash Professional and Flash Builder facilitates importing and updating custom Flex components.
Native support for Adobe AIR
Create applications for the Adobe AIR® runtime with Flash Builder 4, including all the tools required to build, debug, package, and sign AIR applications. Adobe AIR lets you quickly develop RIAs for the desktop using the same skills and codebase you use to build RIAs for the browser.
Code refactoring ENHANCED
Quickly navigate through code or restructure it by renaming all references to a class, method, or variable. Flash Builder 4 adds move refactoring.
Powerful testing tools ENHANCED (Premium edition only)
Accelerate application performance using memory and performance profilers that monitor and analyze memory consumption and CPU cycles. Support for automated functional testing tools such as HP QuickTest Professional is also available.
Network Monitor NEW (Premium edition only)
Generate a detailed audit trail of all data passed between the local Flex application and the back end, assisting with debugging and performance tuning.
Advanced data services ENHANCED
Use open source BlazeDS to add binary, high-performance, HTTP-based data transport, or add the Adobe LiveCycle® Data Services ES2 module for real-time data push and pub/sub messaging.
Command line build NEW (Premium edition only)
Use the new command line build capability to automate your build process.
Flex unit testing integration NEW (Premium edition only)
Automate functional testing using the Flex unit testing framework.
ASDoc support NEW
Display comments in MXML and ActionScript editors using ASDoc.

More info at :

Adobe’s official Flash Builder 4 Product Page

The Official Flex Team Blog post

Adobe Flash Builder 4 and Flash Catalyst public beta available on Adobe Labs

flash_builder Flash Catalyst

Adobe Flash Builder 4  (formely  Flex Builder 4 ) and Adobe Flash Catalyst are out on Adobe Labs going to download and try them out before posting a proper review meanwhile more info on Ryan Stewart’s blog and Andrew Shorten’s Tutorial

fb_beta

Flash Builder 4 delivers a long list of new features, plus improvements to many existing features.There are three main themes to this release: developer productivity, designer-developer workflow, and data-centric application development. For an overview of the features included in this first public beta release, please read Tim Buntel’s What’s New in Flash Builder 4 article and watch the new feature videos. As always, the Flex 4 framework is included within Flash Builder, so please also read Matt Chotin’s What’s New in the Flex 4 SDK article.

fc_beta

Adobe® Flash® Catalyst™ is a new professional interaction design tool for rapidly creating user interfaces without coding.

  • Transform artwork created in Adobe Photoshop® and Adobe Illustrator® into functional user interfaces.
  • Create interactive prototypes with the ability to leverage them in the final product
  • Publish a finished project as a SWF file ready for distribution
  • Work more efficiently with developers who use Adobe Flash Builder™ 4 to create rich Internet applications (RIAs). Designers use Flash Catalyst to create the functional user experience then provide the project file to developers who use Flash Builder to add functionality and integrate with servers and services.

Go get Flash Builder 4

Go get Flash Catalyst
Flash Builder 4 Standalone Installer

Flash Builder 4 Plugin for Eclipse

Flex Component Kit for Adobe Flash Professional CS4

Flex 4 Test Automation Plug-in

Flash Catalyst Beta

More Adobe Resources:
Learn about Flash Builder 4

Learn about Flex 4 SDK

Working with Flash Builder 4