この質問はそのままでは答えられません... すべてのコードが OOP ベースではなく、タイムライン上にあるのに、なぜ個別のクラス ファイルを作成する必要があるのですか? もっと具体的にお願いします。アプリからオブジェクトを作成しようとするときに直面する問題は何ですか?
通常、メインの .fla ファイルのドキュメント プロパティにメイン クラスが必要です。この mainClass は MovieClip を拡張する必要があります。これは org/Main.as の例です。フォルダーに空のフラッシュ ファイルを作成し、その中に「org」という名前のフォルダーを作成します。このコードをこのフォルダー内の Main.as という名前のファイルに配置し、ドキュメント クラス プロパティで org.main をメイン クラスとして設定します。アクション パネルの fla の最初のフレームで:
var aVarOnFirstFrame:String = "some variable value";
この例では、Flash ムービーのメイン コンテナを呼び出す方法と、クラスがドキュメントを操作する方法を示します。これが役立つことを願っています。
変数とメソッドを呼び出す方法がわかります。
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
*/