I have created some code in Actionscript 3 following various tutorials which is a simple media player linked to an XML file for the source information. I have found out though I need to use actionscript classes for the code and wondered is their a way to convert it to classes or does anyone know of a tutorial in actionscript 3 for creating a media player based on classes? My code is below:
import flash.net.URLLoader;
import flash.events.Event;
import flash.net.URLRequest;
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE,xmlloaded);
var xml:XML = new XML();
var amountofvid:Number=0;
var currentvideo:Number=0;
btn_prev.addEventListener (MouseEvent.CLICK, prevvid);
btn_next.addEventListener (MouseEvent.CLICK, nextvid);
loader.load(new URLRequest('videos.xml'));
function xmlloaded (e:Event) {
xml=XML(e.target.data);
amountofvid=xml.video.length ()-1;
changevid();
}
function nextvid (e:Event) {
currentvideo++;
changevid();
}
function prevvid (e:Event) {
currentvideo--;
changevid();
}
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];
}
Any ideas?
Update, thanks for the help guys both helped loads wish I could pick you both a solved answers.
here’s a quick conversion of your code to a classe.
I assumed that it will be associated to a sprite so i extended it as such. If you want to associated the classe to something else, you will want to change this line :
I kept both nextvid and prevvid methods public (meaning you can access it from another level, a parent for example) and your other methods and variables private (accessible from this level only). You might want to change that to suit your need.
For a startup tutorial on how classes works, i would suggest this one on GoToAndLearn.com
http://gotoandlearn.com/play.php?id=43
m.