New
Loading...
Hướng dẫn cách chèn file video FLV vào một file flash sử dụng AS3 đơn giản
Tạo một file FLA trống, chèn đoạn code bên dưới vào một keyframe.


var video:Video = new Video();

    addChild(video);


    var nc:NetConnection = new NetConnection();

    nc.connect(null);


    var ns:NetStream = new NetStream(nc);

    ns.client = {onMetaData:ns_onMetaData, onCuePoint:ns_onCuePoint};


    video.attachNetStream(ns);

    ns.play("http://www.examples.com/video.flv");


    function ns_onMetaData(item:Object):void {

     trace("metaData");

     // Resize video instance.

     video.width = item.width;

     video.height = item.height;

     // Center video instance on Stage.

     video.x = (stage.stageWidth - video.width) / 2;

     video.y = (stage.stageHeight - video.height) / 2;

    }


    function ns_onCuePoint(item:Object):void {

     trace("cuePoint");

     trace(item.name + "\t" + item.time);

    }
Bây giờ bạn chỉ việc thay đường dẫn video http://www.examples.com/video.flv thành đường dẫn video của bạn, lưu tập tin và chạy thử xem nhé.
Lưu ý:
Bạn có thể chỉnh thêm thông số size video bằng cách chỉnh đoạn code

video.width = item.width;

video.height = item.height;
và chỉnh vị trí video trên stage bằng cách chỉnh đoạn code:

video.x = (stage.stageWidth - video.width) / 2;

video.y = (stage.stageHeight - video.height) / 2;
Chúc bạn thành công.