La clase Main, es la madre e importa a las otras 2 importantes: Screengame y Controller
Main.as
Código ActionScript :
public class Main extends Sprite
{
private var screenOfGame:Screengame;
private var controlOfGame:Controller;
public function Main():void
{
screenOfGame = new Screengame();
screenOfGame.startAnimation();
this.addChild(screenOfGame);
controlOfGame = new Controller();
}
}La clases Screengame es la encargada de crear la interfaz del proyecto:
Screengame.as
Código ActionScript :
public function Screengame()
{
this.addChild(screenContainer);
}
public function startGame():void {
trace("EMPIZA LA ANIMACION");
screenContainer.addChild(coinsAdded);
screenContainer.addChild(coinsTotal);
valuesCoins.defaultTextFormat = coinsAdded.textFormatCoin
valuesCoins.text = coinsAdded.getValueCoins() + " / " + coinsTotal.getValueCoins();
screenContainer.addChild(timer);
screenContainer.addChild(player1);
screenContainer.addChild(player2);
this.stopAnimation();
}
Esta clase tiene a su vez algunos metodos publicos que me permiten mostrar o esconder algunos elementos.
Para setear los valores se usa la clase Controller, la cual tiene los botones e inputs que definen los datos y que al hacer click, deberian llamar a los metodos de Screengame para que la aplicacion se actualice:
Código ActionScript :
public class Controller
{
private var gameMode:Screengame;
public function Controller()
{
gameMode = new Screengame();
}
public function showCoin(value:uint):void
{
gameMode.coinsAdded.setValue(value);
}
public function totalCoin(value:uint):void
{
gameMode.coinsTotal.setValue(value);
}
public function startGame(value:uint):void
{
gameMode.timer.setTimeGame(value);
gameMode.startGame();
gameMode.timer.startTimer();
}
}
El problema es que yo he agregado un boton en el controller que me permitiese llamar y ejecutar, como prueba, a los metodos de Screengame
Código ActionScript :
private function menuTemporario():void
{
var mc:cuadradito = new cuadradito();
mc.addEventListener(MouseEvent.CLICK, traceSomething);
mc.x = 100;
mc.y = 100;
this.addChild(mc);
}
public function traceSomething(evt:MouseEvent):void {
trace("HIZO CLICK");
this.startGame(5);
}
la cuestion es que cuando lo hago, el flash me tira un error:
escribió:
at flash.display::DisplayObjectContainer/removeChild()
at uielements::Screengame/stopAnimation()
at uielements::Screengame/startGame()
at Controller/startGame()
at Main/traceSomething()
Entonces, mi pregunta (finalment
Desde ya muchas gracias.
Saludos
