Flex 连接远程服务器(转载)

转载http://hi.baidu.com/udking_love/blog/item/3bd737d1b9a525d4572c84cc.html
在Flex中利用NetConnection, NetStream和Video类显示video文件
2009年02月09日 星期一 下午 10:25

下 面的例子说明了利用NetConnection, NetStream和Video类,如何在Flex应用中显示一个FLV文件,以及如何使用onMetaData和onCuePoint事件处理视频数据 (video meta data)和提示点(cue points)。

  1. xml version = " 1.0 " encoding = " utf-8 " ?>
  2. < mx : Application xmlns : mx = " http://www.adobe.com/2006/mxml "
  3. layout = " vertical "
  4. verticalAlign = " middle "
  5. backgroundColor = " white "
  6. creationComplete = " init(); " viewSourceURL = " srcview/index.html " >
  7. < mx : Script >
  8. [ CDATA [
  9. import mx . utils . ObjectUtil ;
  10. private var nc : NetConnection ;
  11. private var ns : NetStream ;
  12. private var video : Video ;
  13. private var meta : Object ;
  14. private function init () : void {
  15. var nsClient : Object = {} ;
  16. nsClient . onMetaData = ns_onMetaData ;
  17. nsClient . onCuePoint = ns_onCuePoint ;
  18. nc = new NetConnection () ;
  19. nc . connect ( null ) ;
  20. ns = new NetStream ( nc ) ;
  21. ns . play ( " http://www.helpexamples.com/flash/video/cuepoints.flv " ) ;
  22. ns . client = nsClient ;
  23. video = new Video () ;
  24. video . attachNetStream ( ns ) ;
  25. uic . addChild ( video ) ;
  26. }
  27. private function ns_onMetaData ( item : Object ) : void {
  28. trace ( " meta " ) ;
  29. meta = item ;
  30. // Resize Video object to same size as meta data.
  31. video . width = item . width ;
  32. video . height = item . height ;
  33. // Resize UIComponent to same size as Video object.
  34. uic . width = video . width ;
  35. uic . height = video . height ;
  36. panel . title = " framerate: " + item . framerate ;
  37. panel . visible = true ;
  38. trace ( ObjectUtil . toString ( item )) ;
  39. }
  40. private function ns_onCuePoint ( item : Object ) : void {
  41. trace ( " cue " ) ;
  42. }
  43. ]] >
  44. < / mx:Script>
  45. / >
  46. < mx : ControlBar >
  47. < mx : Button label = " Play/Pause " click = " ns.togglePause(); " / >
  48. / >
  49. < / mx:ControlBar>
  50. < / mx : Panel >
  51. < / mx:Application>

具体效果参见原文地址:

http://blog.flexexamples.com/2008/03/01/displaying-a-video-in-flex-using-the-netconnection-netstream-and-video-classes/

你可能感兴趣的:(Flex 连接远程服务器(转载))