Creating External Classes

I have some working main timeline AS 3.0 code that I need to turn into an external class (or multiple classes). But I don’t have any experience writing external classes. What’s the best way of going about this?


import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.display.StageDisplayState;
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextLineMetrics;
import flash.text.AntiAliasType;
import flash.text.TextFormat;
//----------------------------------------------------------------
import flash.utils.getDefinitionByName;
import flash.media.Sound;
import flash.media.SoundLoaderContext;
import flash.media.SoundChannel;
//----------------------------------------------------------------

stage.displayState = StageDisplayState.FULL_SCREEN;
stage.scaleMode = StageScaleMode.NO_SCALE;
 
//----------------------------------------------------------------
content_tb.embedFonts = true;
content_tb.selectable = false;

//----------------------------------------------------------------
var clickSound:Sound;
var librarySoundOne:Class = getDefinitionByName ( "Click" ) as Class;
clickSound = new librarySoundOne();
var clickChannel:SoundChannel;

//----------------------------------------------------------------
var dingSound:Sound;
var librarySoundTwo:Class = getDefinitionByName ( "Ding" ) as Class;
dingSound = new librarySoundTwo();
var dingChannel:SoundChannel;

//----------------------------------------------------------------
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("xml/modernism.xml"));
function LoadXML(e:Event):void {
    xmlData = new XML(e.target.data);
    LoadContent(xmlData);
}
//----------------------------------------------------------------
function LoadContent(textData:XML):void {
    //CONTENT TO BE DISPLAYED ON INITIAL LOAD
    var defaultText = textData.item[0].content.text();
    var pageTitle_text = textData.item.label.text()[0];
    pageTitle_tb.htmlText = "<b>" + pageTitle_text + "</b>";
    var formatSpacing:TextFormat = new TextFormat();
    formatSpacing.letterSpacing = 4;
    pageTitle_tb.setTextFormat(formatSpacing);

    //----------------------------------------

    function setPage(page:Number):void {
        field.scrollV = (page - 1) * linesPerPage + 1;
    }
    // Assigns the text field that is on the stage to a local variable
    var field:TextField = content_tb;  //Added "TextField" type
    field.embedFonts = true;
    // Assign the content to the text field
    field.htmlText = defaultText;

    // Extracts the text format and line height properties
    var format:TextFormat = field.getTextFormat();    //Added "TextFormat" type

    var leading = int(format.leading);
    var extent:TextLineMetrics = field.getLineMetrics(0);
    var ascent = extent.ascent;
    var descent = extent.descent;

    // FIRST CALCULATE THIS NUMBER USING BODY TEXT OF THE SAME FONT SIZE
    // IF HTML TEXT INCLUDES HEADINGS OF DIFFERING SIZES THE NUMBERS WILL BE SKEWED
    //var lineHeight = ascent + descent + leading;
    var lineHeight = 16;
    var linesPerPage = Math.floor((field.height - 4 + leading) / lineHeight);
    var lineCount = (field.maxScrollV - 1) + linesPerPage;
    var pageCount = Math.ceil(lineCount / linesPerPage);

    var offset = (linesPerPage * pageCount) - lineCount + 1;
    var lineBreak:String = "<br />";
    //var lineBreak:String = "
";

    for (var i = 0; i < offset; i++) {
        defaultText.htmlText += lineBreak;
    }
    //LINE BELOW IS A NECESSARY REPEAT
    field.htmlText = defaultText;

    var panelNum = pageCount;
    var curNum = 1;
    pageNum.htmlText = "<b>" + curNum + "</b>";
    pageTotal.htmlText = "<b>" + panelNum + "</b>";
    prevButton_mc.visible = false;

    function NextOnClick(event:MouseEvent):void {
        curNum++;
        pageNum.htmlText = "<b>" + curNum + "</b>";
        setPage(curNum);
        if (curNum == 2) {
            prevButton_mc.visible = true;
            clickChannel = clickSound.play();
        } else if (curNum == panelNum) {
            event.currentTarget.visible = false;
            curNum = panelNum;
            dingChannel = dingSound.play();
        } else {
            clickChannel = clickSound.play();
        }

    }
    nextButton_mc.buttonMode = true;
    nextButton_mc.addEventListener(MouseEvent.CLICK, NextOnClick);

    function PrevOnClick(event:MouseEvent):void {
        curNum--;
        pageNum.htmlText = "<b>" + curNum + "</b>";
        setPage(curNum);
        if (curNum == 1) {
            setPage(curNum);
            event.currentTarget.visible = false;
            curNum = 1;
            dingChannel = dingSound.play();
        } else {
            clickChannel = clickSound.play();
        }
        nextButton_mc.visible = true;
    }
    prevButton_mc.buttonMode = true;
    prevButton_mc.addEventListener(MouseEvent.CLICK, PrevOnClick);
}

Oh yes, there’s a textfield on the stage named “content_tb” and a next and previous button set. And a textfield that holds the page title: “pageTitle_tb”