gpt4 book ai didi

actionscript-3 - ActionScript 3 onMetaData 视频持续时间 - 无法存储值

转载 作者:行者123 更新时间:2023-12-04 05:24:40 25 4
gpt4 key购买 nike

我在 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 值被设置回未识别。
我试图通过推送值来解决 Array 的问题,但同样的事情发生了,Array 重置。可能有什么问题?

编辑:

一旦 onMetaData 完成,任何存储持续时间值的对象都会自毁。我如何实现它并不重要。

最佳答案

您发布的代码无法编译,即使编译成功,也可能导致其他问题。

建议:抛弃元对象,而是设置 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);
}
}
}

关于actionscript-3 - ActionScript 3 onMetaData 视频持续时间 - 无法存储值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13325826/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com