首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Actionscript编译器MTASC和事件

Actionscript编译器MTASC和事件
EN

Stack Overflow用户
提问于 2010-12-09 15:43:59
回答 1查看 170关注 0票数 0

请帮帮忙,如何让netEvent在编译后的flash中工作,比如我甚至不能让macromedia示例工作:

代码语言:javascript
复制
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);

ns.onMetaData = function(infoObject:Object) {
    for (var propName:String in infoObject) {
        trace(propName + " = " + infoObject[propName]);
    }
};

ns.play("http://www.helpexamples.com/flash/video/water.flv");

它必须返回metainfo,但似乎根本没有调用任何事件。我做错了什么?

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2010-12-09 15:51:04

这是来自Adobe文档的正确信息:

代码语言:javascript
复制
package {
import flash.display.Sprite;
import flash.events.NetStatusEvent;
import flash.events.SecurityErrorEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.events.Event;

public class NetConnectionExample extends Sprite {
    private var videoURL:String = "Video.flv";
    private var connection:NetConnection;
    private var stream:NetStream;

    public function NetConnectionExample() {
        connection = new NetConnection();
        connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
        connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
        connection.connect(null);
    }

    private function netStatusHandler(event:NetStatusEvent):void {
        switch (event.info.code) {
            case "NetConnection.Connect.Success":
                connectStream();
                break;
            case "NetStream.Play.StreamNotFound":
                trace("Stream not found: " + videoURL);
                break;
        }
    }

    private function securityErrorHandler(event:SecurityErrorEvent):void {
        trace("securityErrorHandler: " + event);
    }

    private function connectStream():void {
        stream = new NetStream(connection);
        stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
        stream.client = new CustomClient();
        var video:Video = new Video();
        video.attachNetStream(stream);
        stream.play(videoURL);
        addChild(video);
    }
}
}

class CustomClient {
public function onMetaData(info:Object):void {
    trace("metadata: duration=" + info.duration + " width=" + info.width + " height=" + info.height + " framerate=" + info.framerate);
}
public function onCuePoint(info:Object):void {
    trace("cuepoint: time=" + info.time + " name=" + info.name + " type=" + info.type);
}
}

在我看来,你在你发布的代码中遗漏了相当多的东西,并且你不会因为缺少所需的设置代码而得到你想要的东西。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4395971

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档