在编译swf下编译错误

时间:2013-12-26 12:31:31

标签: actionscript-3

在编译时从服务器获取rtmp的问题我得到了这4个错误:   * NewClass.as,Line 30 1120:访问未定义的属性nc。   * NewClass.as,Line 31 1120:访问未定义的属性nc。   * NewClass.as,Line 32 1120:访问未定义的属性nc。   * NewClass.as,Line 33 1120:访问未定义的属性nc。   * NewClass.as,第41行1120:访问未定义的属性nc

我被困了没有想法该怎么做

  package {
    import flash.accessibility.Accessibility;
    import flash.display.Sprite;
    import flash.events.*;
    import flash.net.NetConnection;
    import flash.net.NetStream;
    import flash.media.Video;

    public class NewClass extends Sprite
    {
            public var netStreamObj:NetStream;
//public var nc:NetConnection;
public var vid:Video;

public var streamID:String;
public var videoURL:String;
public var metaListener:Object;

public function RTMP_test () 
{ init_RTMP(); }

function init_RTMP():void
{

    streamID  = "some";
    videoURL = "rtmp://someserver/application/";

    vid = new Video(); 

    nc = new NetConnection();
    nc.addEventListener(NetStatusEvent.NET_STATUS, onConnectionStatus);
    nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
    nc.connect(videoURL);           
}

private function onConnectionStatus(e:NetStatusEvent):void
{
    if (e.info.code == "NetConnection.Connect.Success")
    {
        trace("Creating NetStream");
        netStreamObj = new NetStream(nc);

        metaListener = new Object();
        metaListener.onMetaData = received_Meta;
        netStreamObj.client = metaListener;

        netStreamObj.play(streamID);
        vid.attachNetStream(netStreamObj);
        addChild(vid);
        //intervalID = setInterval(playback, 1000);
    }
}

private function playback():void
{ 
//trace((++counter) + " Buffer length: " + netStreamObj.bufferLength); 
}

public function asyncErrorHandler(event:AsyncErrorEvent):void 
{ trace("asyncErrorHandler.." + "\r"); }

public function onFCSubscribe(info:Object):void
{ trace("onFCSubscribe - succesful"); }

public function onBWDone(...rest):void
{ 
var p_bw:Number; 
if (rest.length > 0)
  { p_bw = rest[0]; }
trace("bandwidth = " + p_bw + " Kbps."); 
}

function received_Meta (data:Object):void
{
var _stageW:int = stage.stageWidth;
var _stageH:int = stage.stageHeight;
var _aspectH:int;
var _videoW:int;
var _videoH:int;

var relationship:Number;
relationship = data.height / data.width;

//Aspect ratio calculated here..
_videoW = _stageW;
_videoH = _videoW * relationship;
_aspectH = (_stageH - _videoH) / 2;

vid.x = 0;
vid.y = _aspectH;
vid.width = _videoW;
vid.height = _videoH;
}
    }
}

1 个答案:

答案 0 :(得分:0)

您已在第12行注释掉变量nc的声明。