Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Error When Streaming Using AS3

Guest
Oct 25, 2013 Oct 25, 2013

Hello Guys, I am trying to stream my webcam using AS3 code but I keep receiving this error message in the output panel when I run the application:

ArgumentError: Error #2126: NetConnection object must be connected.

at flash.net::NetStream/ctor()

at flash.net::NetStream()

At first I listen for the NetStatusEvent status and the connection succeded

But when i include the NetStream class I receive that annoying error. I think this is the relevant code. Any ideas why it isnt working?

import flash.net.NetConnection;
import flash.events.NetStatusEvent;
import flash.net.NetStream;
import flash.media.Camera;
import flash.events.StatusEvent;
import flash.media.Video;
import flash.media.Microphone;

var nc:NetConnection = new NetConnection();

nc.addEventListener(NetStatusEvent.NET_STATUS, netStatus);

nc.connect("rtmfp://localhost/streamCamUrl");

var ns:NetStream = new NetStream(nc);

ns.publish("live", "recording");

function netStatus(event:NetStatusEvent):void{
switch(event.info.code){
 
  case "NetConnection.Connect.Success":
  trace("Connecting up...");
  break;
 
  case "NetConnection.Connect.Failed":
  trace("Unable to Connect");
  break;
 
  case "NetConnection.Connect.Rejected":
  trace("Ouchh!");
  break;
 
  case "NetStream.Connect.Success":
  trace("Thats great!");
  break;
 
  case "NetStream.Connect.Failed":
  trace("Livestream");
  break;
}
}

var cam:Camera = Camera.getCamera();
cam.setMode(520,320,15);
cam.setQuality(0, 80);
ns.attachCamera(cam);

cam.addEventListener(StatusEvent.STATUS, statusHandler);

var vid:Video = new Video();
vid.height = cam.height;
vid.width = cam.width;
vid.attachCamera(cam);

addChild(vid);

var mic:Microphone = Microphone.getEnhancedMicrophone();
mic.gain = 50;
mic.setSilenceLevel(0, 2000);
mic.framesPerPacket = 1;
mic.codec = SoundCodec.SPEEX;
ns.attachAudio(mic);

mic.addEventListener(ActivityEvent.ACTIVITY, this.onMicStatus);


function statusHandler(event:StatusEvent):void{
switch (event.code)
    {
        case "Camera.Muted":
            trace("User clicked Deny.");
            break;
        case "Camera.Unmuted":
            trace("User clicked Accept.");
            break;
    }
}

function onMicStatus(event:StatusEvent):void
{
    if (event.code == "Microphone.Unmuted")
    {
        trace("Microphone access was allowed.");
    } 
    else if (event.code == "Microphone.Muted")
    {
         trace("Microphone access was denied.");
    }
}

TOPICS
ActionScript
2.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 25, 2013 Oct 25, 2013

your ns.publish() method should not execute until your connection succeeds.  move that line of code.

Translate
Community Expert ,
Oct 25, 2013 Oct 25, 2013

your ns.publish() method should not execute until your connection succeeds.  move that line of code.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 26, 2013 Oct 26, 2013

Thanks kglad for your comment. I deleted out the ns.publish method when I executed the code I got a different error...

TypeError: Error #1009: Cannot access a property or method of a null object reference.

at Untitled_fla::MainTimeline/frame1()

Connecting up...

I have been tweaking around with the code but i still couldnt fix the issue. When I debugged the code this appeared in my output:

[SWF] C:\Users\\AppData\Local\Temp\Untitled-1.swf - 3420 bytes after decompression

*** Security Sandbox Violation ***

Connection to rtmfp://localhost/streamCamera halted - not permitted

-- Untrusted local SWFs may not contact the Internet.

SecurityError: Error #2028: Local-with-filesystem SWF file cannot access Internet URL rtmfp://localhost/streamCam.era

at flash.net::NetConnection/connect()

Any advice how to fix this?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 26, 2013 Oct 26, 2013

you mean you moved that line of code, don't you?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 27, 2013 Oct 27, 2013

Yes, Just clarifying I did remove the ns.publish. Then, I got a new error instead . Its confusing.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 27, 2013 Oct 27, 2013

no, don't remove it. move it to your netconnection listener.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 31, 2013 Oct 31, 2013

Sorry to be a nuisance. I hope I don't sound dumb but you mean move the ns.publish method to the netStatus function like this?

switch (info.code) {case "NetConnection.Connect.Success": 

                            ns.publish("live" "recording");

                            trace("CONNECTION SUCCES");
                            break;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 31, 2013 Oct 31, 2013

yes, that should resolve the error message you mentioned.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 04, 2013 Nov 04, 2013

No didnt work! I got the same argument error after putting that line of code in. Sorry, I must be a real pain. Do you put the ns constructor before or after the NetStatus function or doesnt it matter?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 04, 2013 Nov 04, 2013
LATEST

copy and paste your updated code.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines