test.flaのドキュメントクラス内のムービークリップのプロパティにアクセスすると、Test.as test.flaのライブラリは、私がThing.asプロパティpublic var thingStateのにアクセスしようとした2つのムービークリップThingMovieClipとThing2MovieClipスプライト(またはその逆)
を持っていますプロパティ。キャスティングと呼ばれるものを使用して直接 、 は(??)、
逆に、私は私が試した各道の隣になったエラーをコメントし、インスタンス名、動作しませんので、簡単なように見えた 何か、 を割り当てますどのようにMovieClip Thing2MovieClipにThing.as(これはインスタンス化されているのでTest.asの子です)からアクセスできますか?親クラスのオブジェクトは認識できません。ここに2つのクラスがあります:
パッケージcom.hello.test.test { import flash.display.Sprite; import flash.events.Event; import flash.display.DisplayObject; import flash.display.MovieClip;
public class Test extends Sprite
{
public var container:Sprite;
public var thing:Thing; // a Class that extends Sprite that creates a thingGraphic:ThingMovieClip in it from test.fla library
public var thing2Graphic:Thing2MovieClip; // base class is MovieClip, in test.fla library
public function Test()
{
container = new Sprite();
addChild(container);
thing = new Thing();
container.addChild(thing);
thing2Graphic = new Thing2MovieClip();
addChild(thing2Graphic); // adds a Thing2 to stage I presume
addEventListener(Event.ENTER_FRAME, update, false, 0, true);
}
public function update(e:Event):void
{
// trace(container.thing.thingState); // Access of possibly undefined property thing through a reference with static type flash.display:Sprite
if(container.thing.thingState == container.thing.thingState.OFF_)
{
trace("container.thing.thingState = OFF_");
} //1119:Access of possibly undefined property thing through a reference with static type flash.display:Sprite
// trace(container.MovieClip(thing).thingState); //1061: Call to a possibly undefined method MovieClip through a reference with static type flash.display:Sprite
// var child:DisplayObject = container.getChildByName(thing); //Implicit coercion of a value type com.hello.test.test:Thing to an unrelated type String
// trace(child);
}
}
}
パッケージcom.hello.test.test {インポートflash.display.Sprite。 import flash.events.MouseEvent;
public class Thing extends Sprite
{
public var thingGraphic:ThingMovieClip;
public static const ON_:String = "on_";
public static const OFF_:String = "off_";
public var thingState:String;
public function Thing()
{
thingState = OFF_;
buttonMode = true;
useHandCursor = true;
thingGraphic = new ThingMovieClip();
thingGraphic.stop();
addChild(thingGraphic);
this.addEventListener(MouseEvent.MOUSE_DOWN, mousePressed, false, 0, true);
}
public function mousePressed(e:MouseEvent):void
{
trace("pressed");
thingState = ON_;
trace("thingState " +thingState);
thingGraphic.play();
//this.parent.thing2Graphic.play(); // how can I access the thing2 at Test.as (this Class's parent)
// 1119: Access of possibly undefined property thing2 through a reference with static tpe flash.display:DisplayObjectContainer
stage.addEventListener(MouseEvent.MOUSE_UP, mouseReleased, false, 0, true);
}
public function mouseReleased(e:MouseEvent):void
{
thingState = OFF_;
trace("thingState " +thingState);
stage.removeEventListener(MouseEvent.MOUSE_UP, mouseReleased);
thingGraphic.stop();
}
public function update():void
{
trace("updated");
}
}
}
私は、私は、ActionScript 3のいくつかの基本的なもののfundemental理解が欠けていると思うと私はどちらか他のスクリプト/プログラミング言語の他の知識を持っていません。 私がチュートリアルに従うと、彼らはちょうど十分にシンプルに見えますが、次に論理的な使用法であると考えられるものを適用すると、エラーがスローされます。 AS3の簡単な理解、 Foundation AS3.0アニメーション、物事を動かす(素晴らしい本、コンセプトにとどまり、AS3についてはこのような本があったがっていてほしい)、そしてFlash Gamesのエッセンシャルガイド(非常に技術的、そのまま現実に従うことができる)?
おかげで、
ありがとうたくさん(!!)私は、テスト(parent.parent).thing2Graphic.play();また動作します。私はあなたの答えから考えていたので、キャストとそれがなぜ必要なのかを(理解して)読み上げる必要があります。parent.parent.thing2Graphic.play();再び、ありがとう、 – bikutaa
問題はありません。私たちの答えの1つを受け入れて、この質問に回答してください。 – weltraumpirat
'parent.parent'は' DisplayObject'を生成します。厳しいActionscriptで作業するときは、実際に入力を追跡する必要があります。アドビのドキュメント(青いキーワードを強調表示し、特定のヘルプについてはf1を押す)と一緒に構文の強調表示(あなたが「物」などを入力するとポップアップするもの)は、あなたのデータ型を追跡するための道のりになります。 –