Multiple VideoDisplay and playback controls for each using repeater

Problem Summary

I want to dynamically generate a VideoDisplay control and playback controls for each using repeater and data in an XML file.

Solution Summary

Use a component housing the VideoDisplay control and an HBox with Play, Stop, and Pause buttons, and use the component in a Repeater, that takes data from an XML file.

Explanation

See the zip file for the exported project.

----- assets/videos/france.flv -----


----- assets/videos/japan.flv -----

----- data/videoData.xml -----

  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <videos>
  3. <videoname="France"id="france"xlink="assets/videos/france.flv"/>
  4. <videoname="Japan"id="japan"xlink="assets/videos/japan.flv"/>
  5. </videos>

----- components/VideoComp.mxml -----

  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <mx:VBoxxmlns:mx="http://www.adobe.com/2006/mxml"
  3. width="100%"height="100%">
  4. <mx:Script>
  5. <![CDATA[
  6. [Bindable]privatevar_vidData:String;
  7. publicfunctionsetvidData(video:String):void{
  8. _vidData=video;
  9. }
  10. ]]>
  11. </mx:Script>
  12. <mx:VideoDisplayid="vid"
  13. autoPlay="false"source="{_vidData}"/>
  14. <mx:HBox>
  15. <mx:Buttonlabel="Play"click="vid.play();"/>
  16. <mx:Buttonlabel="Pause"click="vid.pause();"/>
  17. <mx:Buttonlabel="Stop"click="vid.stop();"/>
  18. </mx:HBox>
  19. </mx:VBox>

----- MultipleVideos.mxml -----

  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <mx:Applicationxmlns:mx="http://www.adobe.com/2006/mxml"
  3. creationComplete="init()"xmlns:comp="components.*">
  4. <mx:Script>
  5. <![CDATA[
  6. importmx.collections.XMLListCollection;
  7. importmx.rpc.events.ResultEvent;
  8. [Bindable]publicvarvideosDP:XMLListCollection=newXMLListCollection();
  9. privatefunctioninit():void{
  10. videosRequest.send();
  11. }
  12. privatefunctionvideosResultHandler(event:ResultEvent):void{
  13. varlist:XMLList=newXMLList(event.result..video);
  14. videosDP=newXMLListCollection(list);
  15. }
  16. ]]>
  17. </mx:Script>
  18. <mx:HTTPServiceid="videosRequest"useProxy="false"resultFormat="e4x"
  19. result="videosResultHandler(event)"url="data/videoData.xml"/>
  20. <mx:Repeaterid="myRepeater"dataProvider="{videosDP}">
  21. <mx:Labeltext="{'Path:'+myRepeater.currentItem.@xlink}"/>
  22. <comp:VideoCompvidData="{myRepeater.currentItem.@xlink}"/>
  23. </mx:Repeater>
  24. </mx:Application>

Related files for download

You need to have two flv files, france.flv and japan.flv.
MultipleVideos.zip

你可能感兴趣的:(xml,Adobe)