nelco
24.09.2015, 18:51
никак не могу понять этот основной момент ООП :\ как получать доступ к методам вложенных объектов - понятно, а из вложенных объектов как получить ссылку на parent - не могу полностью понять...
в document-классе создаю объекты-контейнеры, из которых нужно вызывать метод document-класса:
public class Main extends Sprite
{
public var floatingCont:FloatingCont;
private var _chapters:Chapters;
private var _codeExamples:CodeExamples;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
public function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
_chapters = new Chapters();
addChild(_chapters);
addChild(_codeExamples = new CodeExamples());
_codeExamples.x = 300;
}
public function fullFillFloatingCont(obj:FloatingCont):void {
if (floatingCont) {
removeChild(floatingCont);
}
floatingCont = new FloatingCont();
floatingCont = obj;
addChild(floatingCont);
}
}
}
мне нужно вызывать метод fullFillFloatingCont из класса _chapters:Chapters
public class Chapters extends Sprite
{
private var _button1:Button;
private var _button2:Button;
private var _floatingCont:FloatingCont;
public function Chapters()
{
_button1 = new Button("кнопка1");
_button2 = new Button("кнопка2");
_button2.y = 200;
addChild(_button1);
addChild(_button2);
_button1.addEventListener(MouseEvent.CLICK, clickListener);
_button2.addEventListener(MouseEvent.CLICK, clickListener);
}
private function clickListener(e:MouseEvent):void
{
switch(e.currentTarget) {
case _button1:
(root as Main).fullFillFloatingCont(new FloatingCont("C://Arrays.as"));
break;
case _button2:
(root as Main).fullFillFloatingCont(new FloatingCont("C://AVScanner.ini"));
break;
}
}
}
}
как в этом классе вместо (root as Main) создать ссылку на Main, чтобы можно было вызывать метод fullFillFloatingCont?
пробовал в поле класса писать что-то типа _main:Main - вообще виснет приложение от такого
в document-классе создаю объекты-контейнеры, из которых нужно вызывать метод document-класса:
public class Main extends Sprite
{
public var floatingCont:FloatingCont;
private var _chapters:Chapters;
private var _codeExamples:CodeExamples;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
public function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
_chapters = new Chapters();
addChild(_chapters);
addChild(_codeExamples = new CodeExamples());
_codeExamples.x = 300;
}
public function fullFillFloatingCont(obj:FloatingCont):void {
if (floatingCont) {
removeChild(floatingCont);
}
floatingCont = new FloatingCont();
floatingCont = obj;
addChild(floatingCont);
}
}
}
мне нужно вызывать метод fullFillFloatingCont из класса _chapters:Chapters
public class Chapters extends Sprite
{
private var _button1:Button;
private var _button2:Button;
private var _floatingCont:FloatingCont;
public function Chapters()
{
_button1 = new Button("кнопка1");
_button2 = new Button("кнопка2");
_button2.y = 200;
addChild(_button1);
addChild(_button2);
_button1.addEventListener(MouseEvent.CLICK, clickListener);
_button2.addEventListener(MouseEvent.CLICK, clickListener);
}
private function clickListener(e:MouseEvent):void
{
switch(e.currentTarget) {
case _button1:
(root as Main).fullFillFloatingCont(new FloatingCont("C://Arrays.as"));
break;
case _button2:
(root as Main).fullFillFloatingCont(new FloatingCont("C://AVScanner.ini"));
break;
}
}
}
}
как в этом классе вместо (root as Main) создать ссылку на Main, чтобы можно было вызывать метод fullFillFloatingCont?
пробовал в поле класса писать что-то типа _main:Main - вообще виснет приложение от такого