0
votes

I need advice about how I'm supposed to be doing this. I have a large application where all the code is on the main timeline in frame1. I've started trying to put the code in class files and telling certain movieclip components to use those class files for thier code. So far I am mostly sucessful but perhaps this is not how I should be doing it.

Main timeline has 8 buttons on it named O1 through O8. I then have a movieclip component in my library which has it's own set of O1 through O8 buttons inside it. This component has been added to the stage it its own layer and given the instance name battleDashboard. I used to access the buttons like this when it was all one big chunk of code (no clases).

O1 //button on the main time line in the main interface battleDashboard.O1 //button inside battleDashboard component

Since creating the class, I've been accessing the buttos inside the component by using "this.O1". The class file is linked using the properties panel for the BattleDashboard movieclip component. It's supposed to be called when a battle occurs and then return to the main interface, hiding itself when done.

Being that I've got over 10,000 lines of code in this app, I really want to have components have their own seperate code. I'm finding that I have to rewrite a lot of functions and include them in the class file that used to be shared. I also have to spend time copying objects and variables using the "public function set" and then retreiving them afterwards using custom events. Am I better off just leaving it all on the main timeline and just having external as files?

1

1 Answers

0
votes

This question cannot be answered as it... Why do you want to make separate class files if all the code is not OOP based and resides on the Timeline? Please be more specific. What is the problem that you face when trying to make Objects from your app???

Normally, you need a main class in the document property of your main .fla file. This mainClass should extends MovieClip. This is an example in org/Main.as Create an empty flash file in a folder, then create a folder inside named "org". Place this code in an file named Main.as in this folder and set org.main as main Class in the document class property. On the first frame of the fla in the actions panel :

var aVarOnFirstFrame:String = "some variable value";

This example show you how to call the main container for your flash movie and how your class may interact with the doc. I hope this will be helpful.

You'll see how to call your variables and methods.

package org {
import flash.display.DisplayObjectContainer;
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.Event;
public class Main extends MovieClip{

    private var mainStageObject:DisplayObjectContainer;
    private var theStage:Stage;

    public function Main(){
        mainStageObject = this.parent;
        theStage = this.stage;
        // Let's call this :
        trace(this + " == \"[object Main]\"\nAND NOT \"[object MainTimeLine]\"");
        trace("which is the default if no main class is specified for the .fla root Document")
        // this.stage is a shortcut to the top level element
        trace(this + ", paced on " + this.parent + " == " + this.stage + " == " + theStage);
        trace("comparaison for the three calls : ");
        var equalityParentStage:Boolean = (this.parent === this.stage);
        var equalityStageAndTheStage:Boolean = (this.stage === theStage);
        var equalityParentAndTheStage:Boolean = (this.parent === theStage);
        var equalityDisplayOContainer:Boolean = (this.parent === mainStageObject);
        var equalityForAllThreeProps:Boolean = ((this.parent === this.stage) && (this.stage === theStage) && (this.parent === mainStageObject));
        trace("this.parent === this.stage ? " + equalityParentStage);
        trace("this.stage === theStage ? " + equalityStageAndTheStage);
        trace("this.parent === theStage ? " + equalityParentAndTheStage);
        trace("this._parent ==== mainStageObject ? " + equalityDisplayOContainer);
        trace("this.parent === this.stage === theStage === mainStageObject ? " + equalityForAllThreeProps);
        this.addEventListener(Event.ADDED_TO_STAGE,onMainIsOnStage,false,0,false);
        this.addEventListener(Event.ACTIVATE,onMainIsActivated,false,0,false);
    }
    private function onMainIsOnStage(e:Event):void{
        trace(e.target.aVarOnFirstFrame);
        // -> outputs : null;
    }
    private function onMainIsActivated(e:Event):void{
        trace(e.target.aVarOnFirstFrame);
        // -> outputs : some variable value;
    }
}
}

/*
[object Main] == "[object Main]"
AND NOT "[object MainTimeLine]"
which is the default if no main class is specified for the .fla root Document
[object Main], paced on [object Stage] == [object Stage] == [object Stage]
comparaison for the three calls : 
this.parent === this.stage ? true
this.stage === theStage ? true
this.parent === theStage ? true
this._parent ==== mainStageObject ? true
this.parent === this.stage === theStage === mainStageObject ? true
null
some variable value
*/