test.fla класс документа Test.as
В библиотеке test.fla есть два мувиклипа ThingMovieClip и Thing2MovieClip
Я попытался получить доступ к свойству Thing.as public var thingState;
непосредственно,
используя что-то под названием Casting (??),
присвоение имени экземпляра,
но то, что казалось таким простым, не работает,
Я прокомментировал ошибки, которые я получал рядом с каждым способом, который я пробовал,
и наоборот, как бы я получил доступ к MovieClip Thing2MovieClip из Thing.as (который является дочерним по отношению к Test.as, потому что именно там он создан), он просто не распознает объект своего родителя, вот два класса:
пакет com.hello.test.test
{
импорт flash.display.Sprite;
импорт flash.events.Event;
import flash.display.DisplayObject;
импорт 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;
импорт 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, и у меня нет других знаний о других языках сценариев / программирования.
когда я точно следую учебным пособиям, они кажутся достаточно простыми, но затем начинают применять то, что я считаю логическим использованием, тогда это вызывает ошибки ..
любые рекомендации книг для простого понимания, то есть технического, но на обычном языке AS3, так как у меня есть Foundation AS3.0 Animation, Make Things Move (отличная книга, придерживается концепций; хотелось бы, чтобы была такая книга о AS3) и Основное руководство по флеш-играм (очень техническое, едва ли может следовать как есть) ??
спасибо,