我在AS3中有标准的NetStream用于视频连接:
守则:
public class VideoInit extends MovieClip
{
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.events.NetStatusEvent;
public var video:Video;
public var nc:NetConnection;
public var ns:NetStream;
public var meta:Object;
public var _duration; // <----- the variable
public function VideoInit()
{
video = new Video(480,270);
addChild(video);
nc = new NetConnection();
nc.connect(null);
ns = new NetStream(nc);
meta = new Object();
ns.client = meta;
video.attachNetStream(ns);
ns.play("video.f4v");
meta = new Object();
meta.onMetaData = function(meta:Object) // <---- the method
{
_duration = meta.duration
}
ns.client = meta;
}
现在,每次onMetaData方法执行时,变量_duration都会存储该值,但在调试器步骤离开方法之后,_duration值将被设置回 unindentified 。 我试图通过推送值来解决Array,但同样的事情发生了,Array重置了。这有什么不对?
修改
只要onMetaData完成,任何存储持续时间值的对象都会自行破坏。我的实施方式并不重要。
答案 0 :(得分:3)
您发布的代码无法编译,即使有,也可能导致其他问题。
建议:抛弃 meta 对象,而是设置 ns.client = this;
这有效:
package
{
import flash.events.Event;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.events.NetStatusEvent;
public class VideoInit extends Sprite
{
private var video:Video;
private var nc:NetConnection;
private var ns:NetStream;
private var _duration:Number; // <----- the variable
public function VideoInit()
{
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
private function onAddedToStage(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
video = new Video(480,270);
addChild(video);
nc = new NetConnection();
nc.connect(null);
ns = new NetStream(nc);
ns.client = this;// meta;
video.attachNetStream(ns);
ns.play("video.f4v");
stage.addEventListener(MouseEvent.MOUSE_DOWN, testTheValueOfDuration);
}
public function onMetaData(e:Object):void
{
_duration = e.duration
trace('_duration:', _duration);
testTheValueOfDuration();
}
private function testTheValueOfDuration(e:MouseEvent = null):void
{
trace('Seriously, what is the value of _duration?', _duration);
}
}
}