0 Replies Latest reply on Jan 1, 2016 12:17 PM by briana93128240

    TypeError: Error #1009: Cannot access a property or method of a null object reference.      at index_fla::MainTimeline/publishP2PVideo()

    briana93128240 Level 1

      whats the cause of the above error? and why does the video freezes when i place a play video? my code is below

       

       

      import flash.net.NetConnection;

       

       

      import flash.events.NetStatusEvent;

       

       

      import flash.media.Camera;

       

       

      import flash.events.MouseEvent;

       

       

      import flash.net.NetStream;

      import flash.net.GroupSpecifier;

      import flash.net.NetStreamMulticastInfo;

      import flash.net.NetGroupSendResult;

      import fl.motion.MotionEvent;

      import flash.net.NetGroup;

       

       

      //step 1

      var CirrusAddress:String = "rtmfp://p2p.rtmfp.net";

      var DeveloperKey:String = "3d142a01affff31a508f31fc-f412604cf122";

       

       

      // step two

      var netConnection:NetConnection;

      // connect to cirrus

      netConnection = new NetConnection();

      netConnection.connect(CirrusAddress, DeveloperKey);

      netConnection.addEventListener(NetStatusEvent.NET_STATUS, netConnectionHandler);

       

       

      /////////////////////////////////////////////// handler function/////////////////////////////////////

      function netConnectionHandler(event:NetStatusEvent):void

      {

        trace ("NetConnection event: " + event.info.code + "\n");

        switch (event.info.code)

        {

        // the connection attempt succeded

        case "NetConnection.Connect.Success":

        trace("NetConnection.connect successful");

        connectSuccess();

        break;

        // the connection was closed succefully

        case "NetConnection.Connect.Closed":

        trace("NetConnection.connect successfully closed");

        break;

        // the connection attempt succeded

        case "NetConnection.Connect.Failed":

        trace("Unable to connect");

        break;

        }

       

        }

      // step three

      function connectSuccess():void{

        trace("connected, my ID:" + netConnection.nearID + "\n");

        nearId.text = netConnection.nearID;

       

       

        }

      //step four

      var outgoingStream:NetStream;

      var incomingStream:NetStream;

       

       

      var camera:Camera;

      camera = Camera.getCamera();

      if (camera)

      {

        camera.setMode(1280,720,24, false);

        camera.setQuality(0,90);

        camera.setKeyFrameInterval(30);

        }

        else

        {

        txtMsg.text = "no camera detected";

        }

        videoPlayback.attachCamera (camera);

       

        // video publish function

      function publishP2PVideo(event:MouseEvent)

      {

        if (!camera)

        {

        Security.showSettings(SecurityPanel.PRIVACY);

        }

        // create a new netstream object for video publishing

       

        outgoingStream new NetStream (netConnection, NetStream.DIRECT_CONNECTIONS);

        outgoingStream.addEventListener(NetStatusEvent.NET_STATUS, nsPublishVideoOnStatus );

        outgoingStream.publish("testVideoName");

        // attach the camera nd microphone to the server

        outgoingStream.attachCamera(camera);

        }

      // publish a video handler function

      function nsPublishVideoOnStatus(infoObject:NetStatusEvent)

      {

        if (infoObject.info.code == "NetStream.Publish.Start")

        {

        trace ("nspublish: "+infoObject.info.code+"("+infoObject.info.description+")");

        txtMsg.text == "publish successful";

        }

        if (infoObject.info.code == "NetStream.publish.StreamNotFound" || infoObject.info.code == "NetStream error"){

        trace (infoObject.info.description);

        }

      }

      // publish video function:

      function playP2PVideo(event:MouseEvent)

      {

        //create a new Netstream Object for video playback

        incomingStream = new NetStream (netConnection, farId.text);

        //trace the NetStream status information

        incomingStream.addEventListener(NetStatusEvent.NET_STATUS, nsPublishVideoOnStatus);

        //subscribe to the named stream

        incomingStream.play("testVideoName");

        //attach the stream

        videoPlayback.attachNetStream(incomingStream);

        }

       

        //play the hndler function

       

       

      function nsPlayVideoOnStatus(infoObject:NetStatusEvent)

      {

        trace("nsplay: "+infoObject.info.code+" ("+infoObject.info.description+")");

        if (infoObject.info.code == "NetStream.Play.Start"){

        trace("nsplay: "+ infoObject.info.code+" ("+infoObject.info.description+")");

       

       

        txtMsg.text = "play successful";

        }

        else if (infoObject.info.code == "NetStream.play.StreamNotFound " || infoObject.info.code == "NetStream Error" )

        {

        trace(infoObject.info.description);

        }

        else if (infoObject.info.code == "NetStream.publish.StreamNotFound " || infoObject.info.code == "NetStream Error"){

      }

       

       

        }

      publishVideo.addEventListener(MouseEvent.CLICK,publishP2PVideo);

      playVideo.addEventListener(MouseEvent.CLICK, playP2PVideo);