function playvideo(path:String, wid:Number=1280, heigt:Number=720):void
{
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.client = this;
ns.addEventListener(NetStatusEvent.NET_STATUS, statusChanged);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
SoundMixer.stopAll();
var vid:Video = new Video();
ns.play(path);
vid.width = wid;
vid.height = heigt;
vid.attachNetStream(ns);
mc_bg.removeChildAt(0);
mc_bg.addChild(vid);
}
问候,这是我的“播放视频”功能。每当我尝试在函数之外移动变量来控制来自其他地方的视频(例如“vid”)时,特定的动画片段和按钮就会消失(不会在舞台上显示)。这是某种错误还是我做错了什么?谢谢!
答案 0 :(得分:1)
这样做:
var vid:Video = new Video();
function playvideo(path:String, wid:Number=1280, heigt:Number=720):void
{
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.client = this;
ns.addEventListener(NetStatusEvent.NET_STATUS, statusChanged);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
SoundMixer.stopAll();
ns.play(path);
vid.width = wid;
vid.height = heigt;
vid.attachNetStream(ns);
mc_bg.removeChildAt(0);
mc_bg.addChild(vid);
}
对于任何var都是一样的,声明外部函数