Jump to content

Newbies and XML video players. Please help.

Recommended Posts

Hi,I have built an XML video player based on a tutorial from the republicofcode.com site. Each thumbnail has a title that loads undernieth it, but I also want to have that same title load in a bar above the thumbnails and videos to show the current title of the video being played. For example if I click on the "video 1" thumbnail, "video 1" displays in the blue bar across the top. Here is a link to a test example. myVideoPlayerHere is my code. You'll notice that I've given it a stab, but not sure what do now. If anyone can help I would be really, really grateful.

package myVideoPlayer{		import flash.display.*;	import flash.text.*;	import flash.events.*;	import flash.net.URLLoader;	import flash.net.URLRequest;	import flash.net.navigateToURL;	import flash.xml.*;	import fl.video.*;		import com.google.analytics.AnalyticsTracker;  	import com.google.analytics.GATracker;	  		public class MyVideoPlayer_Scaredy extends Sprite{						private var thumb_width:Number;		private var thumb_height:Number;		private var thumbs_x:Number;		private var thumbs_y:Number;				private var covers_width:Number;		private var covers_height:Number;		private var covers_x:Number;		private var covers_y:Number;						private var video_x:Number;		private var video_y:Number;		private var my_videos:XMLList;		private var myXML:XML;		private var my_total:Number;		private var main_container:Sprite;				private var thumbs:Sprite;		private var titles:Sprite;		private var header:Sprite;		private var cover:Sprite;		private var my_player:FLVPlayback;		private var i:Number;		private var header_txt:TextField;		private var link_txt:TextField;		private var myFormat:TextFormat;		private var buyBkFmt:TextFormat;				private var tracker:AnalyticsTracker;		private var mySelection:String;				public function MyVideoPlayer_Scaredy(){						trace("Yay!!");			var myXMLLoader:URLLoader = new URLLoader();			myXMLLoader.load(new URLRequest("videoPlaylist.xml"));			myXMLLoader.addEventListener(Event.COMPLETE, processXML);									buyLink.addEventListener(MouseEvent.CLICK, clickBuy);			buyLink.buttonMode = true;						myLogoLink.addEventListener(MouseEvent.CLICK, linkToSrsPg);			myLogoLink.buttonMode = true;			var tracker:AnalyticsTracker = new GATracker( this, "UA-4609680-1", "AS3", false );  			 		}						function processXML(e:Event):void {					 	var myXML:XML = new XML(e.target.data);			thumb_width = myXML.@THUMB_WIDTH;			thumb_height = myXML.@THUMB_HEIGHT;			thumbs_x = myXML.@THUMBS_X;			thumbs_y = myXML.@THUMBS_Y;						covers_width = myXML.@COVERS_WIDTH;			covers_height = myXML.@COVERS_HEIGHT;			covers_x = myXML.@COVERS_X;			covers_y = myXML.@COVERS_Y;						video_x = myXML.@VIDEO_X;			video_y = myXML.@VIDEO_Y;			my_videos = myXML.VIDEO;			my_total = my_videos.length();					trace(myXML.@TITLE);						makeContainers();  			callThumbs();					makePlayer();			callTitle();		}						function linkToSrsPg(e:MouseEvent):void{						navigateToURL(new URLRequest("http://www.kidscanpress.com/US/CitizenKid-C2539.aspx?section=5&series=2"));						var mySelection:String = new String;			mySelection = e.target.name;  			tracker.trackPageview ("seriesLink = " + mySelection);  		}				function clickBuy(e:MouseEvent){			navigateToURL(new URLRequest("http://www.kidscanpress.com/US/How-to-Build-Your-Own-Country-P3151.aspx"));						var mySelection:String = new String;			mySelection = e.target.name;  			tracker.trackPageview ("seriesLink = " + mySelection);  		}				function makeContainers():void{			main_container = new Sprite();			addChild(main_container);						thumbs = new Sprite();			thumbs.addEventListener(MouseEvent.CLICK, playVideo);					thumbs.addEventListener(MouseEvent.MOUSE_OVER, onOver);			thumbs.addEventListener(MouseEvent.MOUSE_OUT, onOut);			thumbs.x = thumbs_x;			thumbs.y = thumbs_y;			thumbs.buttonMode = true;			main_container.addChild(thumbs);						titles = new Sprite();			titles.x = thumbs_x;			titles.y = thumbs_y;			main_container.addChild(titles);					header = new Sprite();			header.x = 0;			header.y = 0;			main_container.addChild(header);						cover = new Sprite();			cover.x = covers_x;			cover.y = covers_y;			main_container.addChild(cover);						trace("my Child");		}				function callThumbs():void{						for (var i:Number = 0; i < my_total; i++){				var thumb_url = my_videos[i].@THUMB;				var thumb_loader = new Loader();				thumb_loader.name = i;				thumb_loader.load(new URLRequest(thumb_url));				thumb_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbLoaded);							thumb_loader.y = 100+10;//distribution of thumbs				thumb_loader.y = (thumb_height+25)*i;//space between thumbs								var cover_url = my_videos[1].@COVER;				var cover_loader = new Loader();				cover_loader.load(new URLRequest(cover_url));				cover_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, coverLoaded);							cover_loader.y = covers_height;								var thumb_title = my_videos[0].@TITLE;//adding thumb titles				var title_txt:TextField = new TextField();				title_txt.text = thumb_title;				title_txt.background = true;				title_txt.backgroundColor = 0xffffff;				title_txt.height = 40;				title_txt.y = thumb_loader.y + title_txt.height + 45;				//title_txt.x = thumb_width + 10; //MOVES TEXT FIELD ALONG X AXIS				title_txt.width = thumb_width;				title_txt.wordWrap = true;				titles.addChild(title_txt);							}		}				function callTitle():void{						var myFormat:TextFormat = new TextFormat();			myFormat.size = 18;			myFormat.font = "Helvetica";			myFormat.bold = true;						var main_title = my_videos[i].@TITLE;//adding  titles			var header_txt:TextField = new TextField();			header_txt.text = main_title;			header_txt.y = 15;			header_txt.x = 20;			header_txt.textColor = 0xFFFFFF;			header_txt.width = 800;			header_txt.height = 30;							header_txt.setTextFormat(myFormat);  			addChild(header_txt);					}						function thumbLoaded(e:Event):void{			var my_thumb:Loader = Loader(e.target.loader);			thumbs.addChild(my_thumb);		}						function coverLoaded(e:Event):void{			var my_cover:Loader = Loader(e.target.loader);			cover.addChild(my_cover);		}						function makePlayer():void{			my_player = new FLVPlayback();			my_player.skin = "SkinUnderPlaySeekStop.swf";			my_player.skinBackgroundColor = 0xAEBEFB;			my_player.skinBackgroundAlpha = 0.5;						my_player.x = video_x - 140;			my_player.y = video_y;			my_player.width = 460;			my_player.height = 340;						my_player.source = my_videos[0].@URL;									my_player.autoPlay = true;						main_container.addChild(my_player);			  		}						function playVideo(event:MouseEvent):void{						var video_url = my_videos[event.target.name].@URL;			my_player.source = video_url;						my_player.seek(0);		}						function onOver (e:MouseEvent):void{			var my_thumb:Loader = Loader(e.target);			my_thumb.alpha = 0.7;		}				function onOut (e:MouseEvent):void{			var my_thumb:Loader = Loader (e.target);			my_thumb.alpha = 1;		}			}}

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...