Getting away from the timeline and embracing some basic OOP structure is the single best thing you can do as a budding flash developer, programmer, or earnest student. Its can be a deep subject, but the sooner you get started figuring it out the better. The googles will explain everything.
At any rate - you have most of what you need to write this procedure into a class. Check out the comments for a brief explanation:
// package encloses the class and identifies its scope
package you.com.app
{
//imports
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.display.Sprite;
import flash.net.URLLoader;
import flash.events.Event;
import flash.net.URLRequest;
import flash.text.TextField;
/**
* ... declare your class, whatever it may extend and any interfaces
*/
public class MediaPlayer extends Sprite
{
// variables now include an access modifier to define their scope (private, here)
private var xml :XML;
private var amountofvid :Number=0;
private var currentvideo :Number=0;
private var loader :URLLoader;
private var vid :MovieClip; //or video component or whatever
private var title :TextField;
private var btn_prev :SimpleButton;
private var btn_next :SimpleButton;
private var currentvideo :int;
/**
* constructor - must match class name. returns statement omitted
*/
public function MediaPlayer()
{
// call superclass
super();
//initialize procedure
init();
}
private function init():void
{
//build display list
assembleDisplayObjects();
//grab data
retreiveData();
}
private function retreiveData():void
{
loader = new URLLoader();
loader.addEventListener(Event.COMPLETE, xmlloaded);
loader.load(new URLRequest('videos.xml'));
}
private function xmlloaded (e:Event):void
{
xml = new XML();
xml=XML(e.target.data);
amountofvid=xml.video.length ()-1;
changevid();
addEventHandlers(); //when data has loaded, activate clickables
}
private function assembleDisplayObjects():void
{
// create or instantiate display objects, and into the display list
// adjust x,y values as needed
vid = new MovieClip();
this.addChild(vid);
title = new TextField();
this.addChild(title);
btn_next = new SimpleButton();
this.addChild(btn_next);
btn_prev = new SimpleButton();
this.addChild(btn_prev);
}
private function addEventHandlers():void
{
//centralized event listener control
btn_prev.addEventListener (MouseEvent.CLICK, prevvid);
btn_next.addEventListener (MouseEvent.CLICK, nextvid);
}
private function nextvid (e:Event):void
{
currentvideo++;
changevid();
}
private function prevvid (e:Event):void
{
currentvideo--;
changevid();
}
private function changevid():void
{
var cv:Number=Math.abs(currentvideo);
if (cv>amountofvid) {
currentvideo=cv=0;
}
if (currentvideo<0) {
currentvideo=cv=amountofvid;
}
vid.source = xml.video.@src[cv];
title.text = xml.video.@title[cv];
}
}
}
I haven't tested this and it's probably not error free, but it is the basic package/class structure and should get you going.
I'd highly recommend Shupe / Rossers "Learning Actionscript 3.0" as a great intro to the subject, and Mook's "Essential Actionscript 3.0" as a comprehensive reference. And google. Lots of google.
Hope that helps.