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

具体效果参见原文地址:

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

你可能感兴趣的:(应用服务器,Flex,Blog,Flash,Adobe)