这个问题无法回答,因为它......如果所有代码都不是基于 OOP 并且驻留在时间轴上,为什么要制作单独的类文件?请更具体。尝试从您的应用程序制作对象时遇到什么问题???
通常,您的主 .fla 文件的文档属性中需要一个主类。这个 mainClass 应该扩展 MovieClip。这是 org/Main.as 中的一个示例 在文件夹中创建一个空的 flash 文件,然后在其中创建一个名为“org”的文件夹。将此代码放在此文件夹中名为 Main.as 的文件中,并在文档类属性中将 org.main 设置为 main Class。在动作面板中 fla 的第一帧:
var aVarOnFirstFrame:String = "some variable value";
此示例向您展示如何调用 Flash 电影的主容器以及您的类如何与 doc 交互。我希望这会有所帮助。
您将看到如何调用变量和方法。
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
*/