package { import flash.display.Sprite; import flash.display.Loader; import flash.display.MovieClip; import flash.events.Event; import flash.net.URLRequest; import com.jeroenwijering.events.*; import mx.events.ResizeEvent; public class Wrapper extends Sprite { private var loader:Loader; public function Wrapper() { init(); [Bindable] /* Pass FlashVars to the Player here. Player.swf should be in the source root of your Flex application */ private var file:String = "player.swf?file=video.flv&" + "controlbar=over&" + "resizing=false"; private var playerObject : Object; /* This method is called when the SWFLoader has completed its loading and the Player has been initialized. Due to timing issues, we have to check whether the player's view has been loaded or not. If not, listen to the Player's new PlayerEvent.READY event. */ private function loaderFinished(e:Event) : void { playerObject = e.target.content as Object; if(playerObject.view == null) { playerObject.addEventListener(PlayerEvent.READY, this.playerReady); } else { playerReady(); } } /* Once the Player has been initialized, we can begin to send and receive events from it */ private function playerReady(e:Event=null) : void { // Wait for the view to load the file. playerObject.view.addViewListener(ViewEvent.LOAD, loadedHandler); // Set the player screen to the correct dimensions. resizePlayer(); } /* The event loading the file has fired, we can now start the video playback. */ private function loadedHandler(e:Event=null):void { playerObject.view.addModelListener(ModelEvent.TIME, timeHandler); playerObject.view.sendEvent(ViewEvent.PLAY, true); } /* To resize the player, simply set its width and height, and send the view a ViewEvent.REDRAW event. */ private function resizePlayer() : void { if(playerObject != null && playerObject.view != null) { playerObject.config['width'] = player.width; playerObject.config['height'] = player.height; playerObject.view.sendEvent(ViewEvent.REDRAW); } } /* Respond to time events */ private function timeHandler(evt:ModelEvent) : void { if(evt.data.position > 3.0) { // Pause the video after 3 seconds) playerObject.view.sendEvent(ViewEvent.PLAY, false); } timelabel.text = "Time tracker: " + evt.data.position; } }//end Wrapper private function init():void { var videoUrl:String = 'video.flv'; loader = new Loader(); //vars = "?config=/config.xml"; var vars:String = "player.swf?"; vars += "file="+videoUrl; vars += "&height=50&width=50"; vars += "&fullscreen=true"; vars += "&allowscriptaccess=always"; loader.load( URLRequest(vars) ); loader.addEventListener(Event.COMPLETE,completeHandler); addChild(loader); } private function completeHandler( evt:Event ):void { trace('completeHandler()!'); MovieClip(loader.content).getController().playItem(undefined); } /* //I have 2 flex buttons play and stop that launch that functions: private function stop():void { MovieClip(loader.content).getController().stopHandler(undefined); } private function play():void { MovieClip(loader.content).getController().playItem(undefined); } */ } //end class }//end package