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 -----
- <?xml version="1.0" encoding="utf-8" ?>
- <videos>
- <video name="France" id="france" xlink="assets/videos/france.flv" />
- <video name="Japan" id="japan" xlink="assets/videos/japan.flv" />
- </videos>
----- components/VideoComp.mxml -----
- <?xml version="1.0" encoding="utf-8"?>
- <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
- width="100%" height="100%">
- <mx:Script>
- <![CDATA[
- [Bindable] private var _vidData:String;
- public function set vidData(video:String):void{
- _vidData = video;
- }
- ]]>
- </mx:Script>
- <mx:VideoDisplay id="vid"
- autoPlay="false" source="{_vidData}"/>
- <mx:HBox>
- <mx:Button label="Play" click="vid.play();"/>
- <mx:Button label="Pause" click="vid.pause();"/>
- <mx:Button label="Stop" click="vid.stop();"/>
- </mx:HBox>
- </mx:VBox>
----- MultipleVideos.mxml -----
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
- creationComplete="init()" xmlns:comp="components.*">
- <mx:Script>
- <![CDATA[
- import mx.collections.XMLListCollection;
- import mx.rpc.events.ResultEvent;
- [Bindable] public var videosDP:XMLListCollection = new XMLListCollection();
- private function init():void{
- videosRequest.send();
- }
- private function videosResultHandler(event:ResultEvent):void{
- var list:XMLList = new XMLList(event.result..video);
- videosDP = new XMLListCollection(list);
- }
- ]]>
- </mx:Script>
- <mx:HTTPService id="videosRequest" useProxy="false" resultFormat="e4x"
- result="videosResultHandler(event)" url="data/videoData.xml"/>
- <mx:Repeater id="myRepeater" dataProvider="{videosDP}">
- <mx:Label text="{'Path:' + myRepeater.currentItem.@xlink}"/>
- <comp:VideoComp vidData="{myRepeater.currentItem.@xlink}"/>
- </mx:Repeater>
- </mx:Application>
Related files for download
You need to have two flv files, france.flv and japan.flv.
MultipleVideos.zip