How would I go about converting my actionscript 3 (on the timeline) into a class? As I am using the same functionality across multiple FLA files.
// IMPORTS
import fl.transitions.*;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.external.ExternalInterface;
// VARIABLES
mcToolTip.toolTip.blendMode = BlendMode.LAYER;
mcToolTip.toolTip.text = "";
var toolio = false;
var settext;
var urlButton1:String = 'URL STRING 1';
var urlButton2:String = 'URL STRING 1';
var urlButton3:String = 'URL STRING 1';
var urlButton4:String = 'URL STRING 1';
var urlButton5:String = 'URL STRING 1';
// MISC
mcButton1.stop();
mcButton2.stop();
mcButton3.stop();
mcButton4.stop();
mcButton5.stop();
mcButton1.buttonMode = true;
mcButton2.buttonMode = true;
mcButton3.buttonMode = true;
mcButton4.buttonMode = true;
mcButton5.buttonMode = true;
// EVENT LISTENERS
//button1
mcButton1.addEventListener(MouseEvent.MOUSE_OVER,mover);
mcButton1.addEventListener(MouseEvent.MOUSE_OUT,mout);
mcButton1.addEventListener(MouseEvent.MOUSE_OVER,button1Text);
mcButton1.addEventListener(MouseEvent.MOUSE_DOWN,callButton1);
mcButton1.addEventListener(MouseEvent.CLICK,mclick);
//button2
mcButton2.addEventListener(MouseEvent.MOUSE_OVER,mover);
mcButton2.addEventListener(MouseEvent.MOUSE_OUT,mout);
mcButton2.addEventListener(MouseEvent.MOUSE_OVER,button2Text);
mcButton2.addEventListener(MouseEvent.MOUSE_DOWN,callButton2);
mcButton2.addEventListener(MouseEvent.CLICK,mclick);
//button3
mcButton3.addEventListener(MouseEvent.MOUSE_OVER,mover);
mcButton3.addEventListener(MouseEvent.MOUSE_OUT,mout);
mcButton3.addEventListener(MouseEvent.MOUSE_OVER,button3Text);
mcButton3.addEventListener(MouseEvent.MOUSE_DOWN,callButton3);
mcButton3.addEventListener(MouseEvent.CLICK,mclick);
//button4
mcButton4.addEventListener(MouseEvent.MOUSE_OVER,mover);
mcButton4.addEventListener(MouseEvent.MOUSE_OUT,mout);
mcButton4.addEventListener(MouseEvent.MOUSE_OVER,button4Text);
mcButton4.addEventListener(MouseEvent.MOUSE_DOWN,callButton5);
mcButton4.addEventListener(MouseEvent.CLICK,mclick);
//button5
mcButton5.addEventListener(MouseEvent.MOUSE_OVER,mover);
mcButton5.addEventListener(MouseEvent.MOUSE_OUT,mout);
mcButton5.addEventListener(MouseEvent.MOUSE_OVER,button5Text);
mcButton5.addEventListener(MouseEvent.MOUSE_DOWN,callButton5);
mcButton5.addEventListener(MouseEvent.CLICK,mclick);
// FUNCTIONS
function mclick(e:MouseEvent):void {
toolio = true;
e.currentTarget.gotoAndStop(5);
e.currentTarget.removeEventListener(MouseEvent.MOUSE_OUT,mout);
e.currentTarget.removeEventListener(MouseEvent.MOUSE_OVER,mover);
settext = mcToolTip.toolTip.text;
if (e.currentTarget !== mcButton2) {
mcButton2.addEventListener(Event.ENTER_FRAME, playReverse);
mcButton2.addEventListener(MouseEvent.MOUSE_OUT, mout);
mcButton2.addEventListener(MouseEvent.MOUSE_OVER,mover);
}
if (e.currentTarget !== mcButton3) {
mcButton3.addEventListener(Event.ENTER_FRAME, playReverse);
mcButton3.addEventListener(MouseEvent.MOUSE_OUT, mout);
mcButton3.addEventListener(MouseEvent.MOUSE_OVER,mover);
}
if (e.currentTarget !== mcButton4) {
mcButton4.addEventListener(Event.ENTER_FRAME, playReverse);
mcButton4.addEventListener(MouseEvent.MOUSE_OUT, mout);
mcButton4.addEventListener(MouseEvent.MOUSE_OVER,mover);
}
if (e.currentTarget !== mcButton1) {
mcButton1.addEventListener(Event.ENTER_FRAME, playReverse);
mcButton1.addEventListener(MouseEvent.MOUSE_OUT, mout);
mcButton1.addEventListener(MouseEvent.MOUSE_OVER,mover);
}
if (e.currentTarget !== mcButton5) {
mcButton5.addEventListener(Event.ENTER_FRAME, playReverse);
mcButton5.addEventListener(MouseEvent.MOUSE_OUT, mout);
mcButton5.addEventListener(MouseEvent.MOUSE_OVER,mover);
}
}
function mover(e:MouseEvent):void {
stopPlayReverse(e.currentTarget as MovieClip);
e.currentTarget.play();
var fadeIn:Tween = new Tween(mcToolTip, "alpha", Strong.easeOut, 0, 1, 0.5, true);
}
function mout(e:MouseEvent):void {
var mc:MovieClip = e.currentTarget as MovieClip;
if (mc !== null) {
mc.addEventListener(Event.ENTER_FRAME, playReverse, false, 0, true);
}
if ( toolio == false ) {
var fadeOut:Tween = new Tween(mcToolTip, "alpha", Strong.easeOut, 1, 0, 0.5, true);
}
if (settext != undefined) {
mcToolTip.toolTip.text = settext;
}
}
function playReverse(e:Event):void {
var mc:MovieClip = e.currentTarget as MovieClip;
if (mc.currentFrame == 1) {
stopPlayReverse(mc);
} else {
mc.prevFrame();
}
}
function stopPlayReverse(mc:MovieClip):void {
if ((mc!==null) && mc.hasEventListener(Event.ENTER_FRAME)) {
mc.removeEventListener(Event.ENTER_FRAME, playReverse);
}
}
function button1Text(e:MouseEvent):void { mcToolTip.toolTip.text = "Menu 1"; }
function button2Text(e:MouseEvent):void { mcToolTip.toolTip.text = "Menu 2"; }
function button3Text(e:MouseEvent):void { mcToolTip.toolTip.text = "Menu 3"; }
function button4Text(e:MouseEvent):void { mcToolTip.toolTip.text = "Menu 4"; }
function button5Text(e:MouseEvent):void { mcToolTip.toolTip.text = "Menu 5"; }
function callButton1(evt:MouseEvent):void { ExternalInterface.call("button1", urlButton1);}
function callButton2(evt:MouseEvent):void { ExternalInterface.call("button2", urlButton2);}
function callButton3(evt:MouseEvent):void { ExternalInterface.call("button3", urlButton3); }
function callButton4(evt:MouseEvent):void { ExternalInterface.call("button4", urlButton4);}
function callButton5(evt:MouseEvent):void { ExternalInterface.call("button5", urlButton5);}
First thing, it appears you have “Automatically declare stage instances” checked in your settings. I avoid this like the plague. Follow the directions here: under “disabling stage instance auto-declaration.” Unchecking that box will force you to declare your other stage instances, like mcToolTip and the mcButtons. But it will help in future development efforts (trust me.)
Anyway, I figured this would be your document class since you said it was used per swf. I named it MyFirstClass, you probably want a better name. You need to chance “BOTH” instances of that name… one in the class signature “public class MyFirstClass extends MovieClip” and the second in the constructor (the function with the same name as the class) which gets run as soon as the class is “instantiated“
Put this file in the same directory as your .fla. Add “MyFirstClass” as the document class.
Read up on more info about how to write your own class: here