Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4320984
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T08:41:36+00:00 2026-05-21T08:41:36+00:00

I have created some code in Actionscript 3 following various tutorials which is a

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T08:41:36+00:00Added an answer on May 21, 2026 at 8:41 am

    here’s a quick conversion of your code to a classe.

    package  {
    
    import flash.net.URLLoader;
    import flash.events.Event;
    import flash.net.URLRequest;    
    
    public class mediaPlayer extends Sprite {
    
        private var loader:URLLoader;
        private var xml:XML;
        private var amountofvid:Number=0;
        private var currentvideo:Number=0;
    
        public function mediaPlayer() {
    
            loader = new URLLoader();
            loader.addEventListener(Event.COMPLETE,xmlloaded);
            btn_prev.addEventListener (MouseEvent.CLICK, prevvid);
            btn_next.addEventListener (MouseEvent.CLICK, nextvid);
            loader.load(new URLRequest('videos.xml'));
    
        }
    
        private function xmlloaded (e:Event) {
            xml = new XML();
            xml=XML(e.target.data);
            amountofvid=xml.video.length()-1;
            changevid();
        }
    
        public function nextvid (e:Event) {
            currentvideo++;
            changevid();
        }
    
        public function prevvid (e:Event) {
            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 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 :

    public class mediaPlayer extends Sprite {
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a small Java application in which there is some code that
I have some code that I have created for an OnChange event which works
I have created a class library in VB .NET. Some code in the library
I have created a report in MS Access report and write some VBA code
I have some code which I did not originally create that uses _beginthreadex and
I have created a .NET DLL which makes some methods COM visible. One method
Does anyone have some useful beginner tutorials and code snippets for playing with basic
I have some code (which I cannot change) that I need to get working
Hey, sorry for my bad english... Using EF4 code-only, I have created some POCO
I have created some code that emails an html email to a given address.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.