如何将netstream.appendBytes()用于http动态流?

时间:2010-07-10 20:27:44

标签: flash flash-cs4 actionscript-3 flash-cs5

我试图弄清楚如何在Flash 10.1中使用http动态流,但我无法使基本功能正常工作。将appendbytes与视频文件一起使用的语法是什么?

package com.player {

import flash.display.Stage;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.media.Video;
import flash.display.Sprite;
import flash.net.URLRequest;
import flash.net.URLStream;
import flash.events.Event;
import flash.utils.ByteArray;

public class Player extends Sprite {

    const vurl = "file://E:/clip.flv"

    private var nc:NetConnection;
    private var ns:NetStream;
    private var vo:Video;



    private var urlstream:URLStream;

    public function Player() {

        nc = new NetConnection();
        nc.connect(null);

        ns = new NetStream(nc);
        ns.client = new StreamClient();

        vo = new Video();
        vo.attachNetStream(ns);

        addChild(vo);

        ns.play(vurl);

        var urlrequest:URLRequest = new URLRequest(vurl)
         urlstream = new URLStream();

        urlstream.addEventListener(Event.COMPLETE, completeHandler);

        urlstream.load(urlrequest);



    }

    private function completeHandler(event:Event):void {
        trace("completeHandler: " + event);

        var bytes:ByteArray = new ByteArray();

        urlstream.readBytes(bytes);

        ns.appendBytes(bytes);
    }


}

}

运行此操作会给我一个错误:

  

TypeError:错误#2004:其中一个参数无效。       在flash.net::NetStream/appendBytes()       在......

1 个答案:

答案 0 :(得分:2)

我找到了解决问题的方法。您必须以ns.play(null)而不是ns.play('url to download');

开头