Avg. Rating 3.8

Problem

You need to embed a single YouTube video inside your Flex Application.

Solution

YouTube videos are Flash objects, so we can simply use SWFLoader to place the video inside Flex.

Detailed explanation

Bascially, all you need to do is copy the embed html from the YouTube.com page for the video you want to appear in your Flex application. Then load the url in that embed code into a SWFLoader in your application.

 


<?xml version="1.0"

encoding="utf-8"?>
<mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml "

layout="
absolute " verticalAlign=" top "

creationComplete="
Init (); " backgroundGradientAlphas=" [1.0, 1.0] " backgroundGradientColors=" [#EE3636, #308A3F] " viewSourceURL=" srcview/index.html " > <mx:Script> <! [ CDATA [ private function Init () : void { var url : String = "http://www.youtube.com/v/zlfKdbWwruY&hl=en&fs=1"; //url extracted from embed code

Security. allowDomain ( url ); //allow domain

youtubevid. load ( url ); //load video

} ]] > </mx:Script> <mx:VBox width=" 100% " height=" 100% " horizontalAlign=" center " verticalAlign=" top " verticalGap=" 0 " > <mx:Label text=" YouTube Video Embedded Inside Flex " width=" 100% " color=" #060809 " textAlign=" center " fontSize=" 16 " fontWeight=" bold " /> <mx:SWFLoader id=" youtubevid " verticalAlign=" top " horizontalAlign=" center " width=" 425 " height=" 344 " /> </mx:VBox> </mx:Application>

 

Live Example: http://www.brentlamborn.com/examples/Flex_youtube/

View Source: http://www.brentlamborn.com/examples/Flex_youtube/srcview/index.html

Brent Lamborn

Report abuse

Related recipes