Avatar of lowsky13
lowsky13

asked on 

NetStream publish

So if I comment out the last two lines in my code then my swf runs without error and tells me that I have connected. However, when any of the last two lines I get errors.

I get  Error #2126: NetConnection object must be connected...What doe I need to do to get this to work?
var livestream:NetConnection = new NetConnection();
livestream.objectEncoding = ObjectEncoding.AMF0;
livestream.client = this;
livestream.addEventListener( NetStatusEvent.NET_STATUS , netStatus );
livestream.connect("rtmp://domain.com/oflaDemo");
 
var hostStream:NetStream = new NetStream(livestream);
hostStream.publish("lecture", "live");

Open in new window

Adobe FlashScripting Languages

Avatar of undefined
Last Comment
asaivan
Avatar of asaivan
asaivan
Flag of United States of America image

You need to set your netStatus method to listen for the following string:
function netStatus(event:NetStatusEvent):void
{
  if (event.info.code == "NetConnection.Connect.Success")
  {
    var hostStream:NetStream = new NetStream(livestream);
    hostStream.publish("lecture", "live");
  }
}
 
 
//But you will probably want to declare your hostStream variable before you put it //in the netStatus method.
    

Open in new window

Avatar of lowsky13
lowsky13

ASKER

I did what you said...and added  goLive.addEventListener(MouseEvent.CLICK, netStatus) and when I click on my mc button then it gives me the following error:

TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::MouseEvent@1d3520e1 to flash.events.NetStatusEvent.
Avatar of asaivan
asaivan
Flag of United States of America image

That's because of the strong typing in AS3, you can't have an event of a certain type being handled by a method which only accepts events of a different type.  If you want this to work in response to a mouse click, then you should put your livestream object in a method which is triggered on a mouse click.  

Make sense?
Avatar of lowsky13
lowsky13

ASKER

I think I'm following you but I didn't get the most important part...

"you should put your livestream object in a method which is triggered on a mouse click."

So I'm trying to learn but sorry if my interpretation is terrible but...

So the livestream object which is the netconnection...I need to put that in another function? What method triggers a mouse click...event:Event?
Avatar of asaivan
asaivan
Flag of United States of America image

The following code should help :)
goLive.addEventListener(MouseEvent.CLICK, mouseClickHandler);
 
function mouseClickHandler(event:MouseClick):void
{
 var livestream:NetConnection = new NetConnection();
 livestream.objectEncoding = ObjectEncoding.AMF0;
 livestream.client = this;
 livestream.addEventListener( NetStatusEvent.NET_STATUS , netStatus );
 livestream.connect("rtmp://domain.com/oflaDemo");
}
 
  

Open in new window

Avatar of lowsky13
lowsky13

ASKER

O.K. so when I click on the button it says Success but it is not publishing...do you know why? I put the brackets around netStatusCheck() but it threw me an error.
function netStatusCheck(event:NetStatusEvent):void
{
  if (event.info.code == "NetConnection.Connect.Success")
  {
	hostStream = new NetStream(livestream);
    hostStream.publish("lecture", "live");
	trace("We are live");
  }
}
 
 
goLive.addEventListener(MouseEvent.CLICK, mouseClickHandler);
 
function mouseClickHandler(event:MouseEvent):void
{
 var livestream:NetConnection = new NetConnection();
 livestream.objectEncoding = ObjectEncoding.AMF0;
 livestream.client = this;
 livestream.addEventListener( NetStatusEvent.NET_STATUS , netStatus );
 livestream.connect("rtmp://domain.com/oflaDemo");
 netStatusCheck;
 
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of asaivan
asaivan
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of lowsky13
lowsky13

ASKER

I did all that...it still is not tracing out my netStatusCheck. How would I get netStatusCheck to initiate if it is in another function? I have tried putting it all in the same function with no luck.
Avatar of asaivan
asaivan
Flag of United States of America image

Can you post your entire code?  I will review and edit, if necesary.
Avatar of lowsky13
lowsky13

ASKER

O.K. got it...I had some misspellings. Thanks.
Avatar of lowsky13
lowsky13

ASKER

Is it the same thing to play a live stream but instead of publish you use play?
Avatar of asaivan
asaivan
Flag of United States of America image

For a live stream, yes, you would use play.
Scripting Languages
Scripting Languages

A scripting language is a programming language that supports scripts, programs written for a special run-time environment that automate the execution of tasks that could alternatively be executed one-by-one by a human operator. Scripting languages are often interpreted (rather than compiled). Primitives are usually the elementary tasks or API calls, and the language allows them to be combined into more complex programs. Environments that can be automated through scripting include software applications, web pages within a web browser, the shells of operating systems (OS), embedded systems, as well as numerous games. A scripting language can be viewed as a domain-specific language for a particular environment; in the case of scripting an application, this is also known as an extension language.

30K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo