francais
11-27-2009, 05:41 AM
Hi im sorry but im still new in AS3 so I'll be needing your help :confused:
Im having problem with "PREPAREBUTTONLISTENERS" - errors marked in RED
Im trying to call to a function where the game will restart and clear its values eg. bet, pot value, etc
PROBLEM: im getting this error:
1120: Access of undefined property yesGame_btn
1120: Access of undefined property noGame_btn
PS: Can't post the whole code because it's too long.
{
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.text.TextField;
import flash.display.SimpleButton;
import flash.ui.Mouse;
import flash.utils.Timer;
import flash.system.fscommand;
/**
* ...
* @author DefaultUser (Tools -> Custom Arguments...)
*/
public class GameScreen extends MovieClip
{
private var _coinsFall:CoinsFall;
private var _results:*;
private var _tossAnim:*;
private var _winAnim:*;
private var _drawAnim:*;
private var _loseAnim:*;
private var _drawCounter:int = 0;
private var _url:String = new String();
public function GameScreen():void
{
addEventListener( Event.ADDED_TO_STAGE, init );
addEventListener( Event.REMOVED_FROM_STAGE, dispose );
}
public function hideScreen():void
{
this.visible = false;
}
public function showScreen():void
{
this.visible = true;
}
private function init( e:Event = null):void
{
hideScreen();
removeEventListener( Event.ADDED_TO_STAGE, init );
prepareButtonListeners( bet5_btn );
prepareButtonListeners( bet10_btn );
prepareButtonListeners( bet20_btn );
prepareButtonListeners( yes_btn );
prepareButtonListeners( no_btn );
prepareButtonListeners( yesGame_btn ); //PROBLEM HERE
prepareButtonListeners( noGame_btn ); //PROBLEM HERE
prepareButtonListeners( help_btn );
prepareButtonListeners( quit_btn );
error_mc.visible = false;
error_txt.visible = false;
betIdle5.visible = false;
betIdle10.visible = false;
betIdle20.visible = false;
fly5.addEventListener( "FlyDown", afterFly );
fly10.addEventListener( "FlyDown", afterFly );
fly20.addEventListener( "FlyDown", afterFly );
bubble_mc.visible = false;
hideGUI();
showInterface();
showIntroB();
updateGUI();
hideDoubleUp();
hideWinPanel();
hideLosePanel();
}
private function dispose( e:Event ):void
{
removeEventListener( Event.REMOVED_FROM_STAGE, dispose );
removeButtonListeners( bet5_btn );
removeButtonListeners( bet10_btn );
removeButtonListeners( bet20_btn );
removeButtonListeners( yes_btn );
removeButtonListeners( no_btn );
removeButtonListeners( yesGame_btn ); //PROBLEM HERE
removeButtonListeners( noGame_btn ); //PROBLEM HERE
removeButtonListeners( help_btn );
removeButtonListeners( quit_btn );
}
private function showIntroB():void
{
introbubble_mc.visible = true;
bet5.gotoAndPlay("blink");
bet10.gotoAndPlay("blink");
bet20.gotoAndPlay("blink");
}
private function hideInterface():void
{
help_btn.enabled = false;
quit_btn.enabled = false;
trace("hidden");
}
private function showInterface():void
{
help_btn.enabled = true;
quit_btn.enabled = true;
}
private function hideIntroB():void
{
introbubble_mc.visible = false;
bet5.gotoAndStop( "idle" );
bet10.gotoAndStop( "idle" );
bet20.gotoAndStop( "idle" );
}
private function hideGUI():void
{
potValue_txt.visible = false;
serialNum_txt.visible = false;
}
private function showGUI():void
{
potValue_txt.visible = true;
serialNum_txt.visible = true;
}
public function updateGUI():void
{
userName_txt.text = String( GlobalVariables.userName );
balance_txt.text = String( GlobalVariables.userCash );
serialNum_txt.text = String( GlobalVariables.userSerialNumber );
potValue_txt.text = String( GlobalVariables.potValue );
}
private function showError( description:String ):void
{
error_txt.text = description;
error_mc.visible = true;
error_txt.visible = true;
}
private function prepareButtonListeners( e:* ):void
{
e.addEventListener( MouseEvent.CLICK, exitClick );
e.addEventListener( MouseEvent.CLICK, btnClick );
e.addEventListener( MouseEvent.MOUSE_OVER, btnOver );
e.addEventListener( MouseEvent.MOUSE_OUT, btnOut );
}
private function removeButtonListeners( e:* ):void
{
e.removeEventListener( MouseEvent.CLICK, exitClick );
e.removeEventListener( MouseEvent.CLICK, btnClick );
e.removeEventListener( MouseEvent.MOUSE_OVER, btnOver );
e.removeEventListener( MouseEvent.MOUSE_OUT, btnOut );
}
private function exitClick( e:MouseEvent ):void
{
switch( e.target.name )
{
case "help_btn":
GlobalVariables.instructionScreen = new InstructionScreen();
addChild( GlobalVariables.instructionScreen );
break;
case "quit_btn":
trace("exit game");
fscommand("Quit");
break;
}
}
private function btnClick( e:MouseEvent ):void
{
//trace( "CLICK", e.target.name );
showGUI();
hideIntroB();
hideInterface();
switch( e.target.name ) {
case "bet5_btn":
if ( GlobalVariables.gameMode != "BETTING" ) return;
hideWinPanel();
hideInterface();
betIdle5.visible = false;
betIdle10.visible = true;
betIdle20.visible = true;
fly5.gotoAndPlay( "s1" );
GlobalVariables.gameMode = "BET";
bet5.gotoAndStop( "idle" );
//GlobalVariables.userCash -= 5;
GlobalVariables.bet = 5;
GlobalVariables.potValue += 10;
updateGUI();
//decideResult();
WebServiceHandler.doGetWhat( "getgame", "2021", "" );
break;
case "bet10_btn":
if ( GlobalVariables.gameMode != "BETTING" ) return;
hideWinPanel();
hideInterface();
betIdle5.visible = true;
betIdle10.visible = false;
betIdle20.visible = true;
fly10.gotoAndPlay( "s1" );
GlobalVariables.gameMode = "BET";
bet10.gotoAndStop( "idle" );
//GlobalVariables.userCash -= 10;
GlobalVariables.bet = 10;
GlobalVariables.potValue += 20;
updateGUI();
//decideResult();
WebServiceHandler.doGetWhat( "getgame", "2022", "" );
break;
case "bet20_btn":
if ( GlobalVariables.gameMode != "BETTING" ) return;
hideWinPanel();
hideInterface();
betIdle5.visible = true;
betIdle10.visible = true;
betIdle20.visible = false;
fly20.gotoAndPlay( "s1" );
GlobalVariables.gameMode = "BET";
bet20.gotoAndStop( "idle" );
//GlobalVariables.userCash -= 20;
GlobalVariables.bet = 20;
GlobalVariables.potValue += 40;
updateGUI();
//decideResult();
WebServiceHandler.doGetWhat( "getgame", "2023", "" );
break;
case "yesGame_btn": //FUNCTION PROBLEM HERE
showIntroB();
hideWinPanel();
hideLosePanel();
break;
case "noGame_btn":
fscommand("quit");
trace("GAME CLOSE");
break;
case "yes_btn":
GlobalVariables.gameMode = "BET";
//loadTossAnimation();
_drawCounter++;
hideDoubleUp();
//idle_mc.visible = false;
//DOUBLE BET
GlobalVariables.potValue *= 2;
GlobalVariables.bet *= 2;
//GlobalVariables.userCash -= GlobalVariables.potValue;
//updateGUI();
switch( GlobalVariables.bet ) {
case 10:
WebServiceHandler.doGetWhat( "getgame", "2022", "" );
break;
case 20:
WebServiceHandler.doGetWhat( "getgame", "2023", "" );
break;
case 40:
WebServiceHandler.doGetWhat( "getgame", "2024", "" );
break;
case 80:
WebServiceHandler.doGetWhat( "getgame", "2025", "" );
break;
case 160:
WebServiceHandler.doGetWhat( "getgame", "2026", "" );
break;
}
break;
case "no_btn":
GlobalVariables.gameMode = "BET-NO";
//loadTossAnimation();
_drawCounter++;
hideDoubleUp();
//idle_mc.visible = false;
//DOUBLE BET
//GlobalVariables.potValue *= 2;
//GlobalVariables.userCash -= GlobalVariables.potValue;
//updateGUI();
switch( GlobalVariables.bet )
{
case 5:
WebServiceHandler.doGetWhat( "getgame", "2021", "" );
break;
case 10:
WebServiceHandler.doGetWhat( "getgame", "2022", "" );
break;
case 20:
WebServiceHandler.doGetWhat( "getgame", "2023", "" );
break;
case 40:
WebServiceHandler.doGetWhat( "getgame", "2024", "" );
break;
case 80:
WebServiceHandler.doGetWhat( "getgame", "2025", "" );
break;
case 160:
WebServiceHandler.doGetWhat( "getgame", "2026", "" );
break;
}
//ORIGINAL
//GlobalVariables.gameMode = "BETTING";
//hideDoubleUp();
//
//RETURN VALUE
//GlobalVariables.userCash += GlobalVariables.potValue;
//GlobalVariables.potValue = 0;
//updateGUI();
break;
}
Im having problem with "PREPAREBUTTONLISTENERS" - errors marked in RED
Im trying to call to a function where the game will restart and clear its values eg. bet, pot value, etc
PROBLEM: im getting this error:
1120: Access of undefined property yesGame_btn
1120: Access of undefined property noGame_btn
PS: Can't post the whole code because it's too long.
{
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.text.TextField;
import flash.display.SimpleButton;
import flash.ui.Mouse;
import flash.utils.Timer;
import flash.system.fscommand;
/**
* ...
* @author DefaultUser (Tools -> Custom Arguments...)
*/
public class GameScreen extends MovieClip
{
private var _coinsFall:CoinsFall;
private var _results:*;
private var _tossAnim:*;
private var _winAnim:*;
private var _drawAnim:*;
private var _loseAnim:*;
private var _drawCounter:int = 0;
private var _url:String = new String();
public function GameScreen():void
{
addEventListener( Event.ADDED_TO_STAGE, init );
addEventListener( Event.REMOVED_FROM_STAGE, dispose );
}
public function hideScreen():void
{
this.visible = false;
}
public function showScreen():void
{
this.visible = true;
}
private function init( e:Event = null):void
{
hideScreen();
removeEventListener( Event.ADDED_TO_STAGE, init );
prepareButtonListeners( bet5_btn );
prepareButtonListeners( bet10_btn );
prepareButtonListeners( bet20_btn );
prepareButtonListeners( yes_btn );
prepareButtonListeners( no_btn );
prepareButtonListeners( yesGame_btn ); //PROBLEM HERE
prepareButtonListeners( noGame_btn ); //PROBLEM HERE
prepareButtonListeners( help_btn );
prepareButtonListeners( quit_btn );
error_mc.visible = false;
error_txt.visible = false;
betIdle5.visible = false;
betIdle10.visible = false;
betIdle20.visible = false;
fly5.addEventListener( "FlyDown", afterFly );
fly10.addEventListener( "FlyDown", afterFly );
fly20.addEventListener( "FlyDown", afterFly );
bubble_mc.visible = false;
hideGUI();
showInterface();
showIntroB();
updateGUI();
hideDoubleUp();
hideWinPanel();
hideLosePanel();
}
private function dispose( e:Event ):void
{
removeEventListener( Event.REMOVED_FROM_STAGE, dispose );
removeButtonListeners( bet5_btn );
removeButtonListeners( bet10_btn );
removeButtonListeners( bet20_btn );
removeButtonListeners( yes_btn );
removeButtonListeners( no_btn );
removeButtonListeners( yesGame_btn ); //PROBLEM HERE
removeButtonListeners( noGame_btn ); //PROBLEM HERE
removeButtonListeners( help_btn );
removeButtonListeners( quit_btn );
}
private function showIntroB():void
{
introbubble_mc.visible = true;
bet5.gotoAndPlay("blink");
bet10.gotoAndPlay("blink");
bet20.gotoAndPlay("blink");
}
private function hideInterface():void
{
help_btn.enabled = false;
quit_btn.enabled = false;
trace("hidden");
}
private function showInterface():void
{
help_btn.enabled = true;
quit_btn.enabled = true;
}
private function hideIntroB():void
{
introbubble_mc.visible = false;
bet5.gotoAndStop( "idle" );
bet10.gotoAndStop( "idle" );
bet20.gotoAndStop( "idle" );
}
private function hideGUI():void
{
potValue_txt.visible = false;
serialNum_txt.visible = false;
}
private function showGUI():void
{
potValue_txt.visible = true;
serialNum_txt.visible = true;
}
public function updateGUI():void
{
userName_txt.text = String( GlobalVariables.userName );
balance_txt.text = String( GlobalVariables.userCash );
serialNum_txt.text = String( GlobalVariables.userSerialNumber );
potValue_txt.text = String( GlobalVariables.potValue );
}
private function showError( description:String ):void
{
error_txt.text = description;
error_mc.visible = true;
error_txt.visible = true;
}
private function prepareButtonListeners( e:* ):void
{
e.addEventListener( MouseEvent.CLICK, exitClick );
e.addEventListener( MouseEvent.CLICK, btnClick );
e.addEventListener( MouseEvent.MOUSE_OVER, btnOver );
e.addEventListener( MouseEvent.MOUSE_OUT, btnOut );
}
private function removeButtonListeners( e:* ):void
{
e.removeEventListener( MouseEvent.CLICK, exitClick );
e.removeEventListener( MouseEvent.CLICK, btnClick );
e.removeEventListener( MouseEvent.MOUSE_OVER, btnOver );
e.removeEventListener( MouseEvent.MOUSE_OUT, btnOut );
}
private function exitClick( e:MouseEvent ):void
{
switch( e.target.name )
{
case "help_btn":
GlobalVariables.instructionScreen = new InstructionScreen();
addChild( GlobalVariables.instructionScreen );
break;
case "quit_btn":
trace("exit game");
fscommand("Quit");
break;
}
}
private function btnClick( e:MouseEvent ):void
{
//trace( "CLICK", e.target.name );
showGUI();
hideIntroB();
hideInterface();
switch( e.target.name ) {
case "bet5_btn":
if ( GlobalVariables.gameMode != "BETTING" ) return;
hideWinPanel();
hideInterface();
betIdle5.visible = false;
betIdle10.visible = true;
betIdle20.visible = true;
fly5.gotoAndPlay( "s1" );
GlobalVariables.gameMode = "BET";
bet5.gotoAndStop( "idle" );
//GlobalVariables.userCash -= 5;
GlobalVariables.bet = 5;
GlobalVariables.potValue += 10;
updateGUI();
//decideResult();
WebServiceHandler.doGetWhat( "getgame", "2021", "" );
break;
case "bet10_btn":
if ( GlobalVariables.gameMode != "BETTING" ) return;
hideWinPanel();
hideInterface();
betIdle5.visible = true;
betIdle10.visible = false;
betIdle20.visible = true;
fly10.gotoAndPlay( "s1" );
GlobalVariables.gameMode = "BET";
bet10.gotoAndStop( "idle" );
//GlobalVariables.userCash -= 10;
GlobalVariables.bet = 10;
GlobalVariables.potValue += 20;
updateGUI();
//decideResult();
WebServiceHandler.doGetWhat( "getgame", "2022", "" );
break;
case "bet20_btn":
if ( GlobalVariables.gameMode != "BETTING" ) return;
hideWinPanel();
hideInterface();
betIdle5.visible = true;
betIdle10.visible = true;
betIdle20.visible = false;
fly20.gotoAndPlay( "s1" );
GlobalVariables.gameMode = "BET";
bet20.gotoAndStop( "idle" );
//GlobalVariables.userCash -= 20;
GlobalVariables.bet = 20;
GlobalVariables.potValue += 40;
updateGUI();
//decideResult();
WebServiceHandler.doGetWhat( "getgame", "2023", "" );
break;
case "yesGame_btn": //FUNCTION PROBLEM HERE
showIntroB();
hideWinPanel();
hideLosePanel();
break;
case "noGame_btn":
fscommand("quit");
trace("GAME CLOSE");
break;
case "yes_btn":
GlobalVariables.gameMode = "BET";
//loadTossAnimation();
_drawCounter++;
hideDoubleUp();
//idle_mc.visible = false;
//DOUBLE BET
GlobalVariables.potValue *= 2;
GlobalVariables.bet *= 2;
//GlobalVariables.userCash -= GlobalVariables.potValue;
//updateGUI();
switch( GlobalVariables.bet ) {
case 10:
WebServiceHandler.doGetWhat( "getgame", "2022", "" );
break;
case 20:
WebServiceHandler.doGetWhat( "getgame", "2023", "" );
break;
case 40:
WebServiceHandler.doGetWhat( "getgame", "2024", "" );
break;
case 80:
WebServiceHandler.doGetWhat( "getgame", "2025", "" );
break;
case 160:
WebServiceHandler.doGetWhat( "getgame", "2026", "" );
break;
}
break;
case "no_btn":
GlobalVariables.gameMode = "BET-NO";
//loadTossAnimation();
_drawCounter++;
hideDoubleUp();
//idle_mc.visible = false;
//DOUBLE BET
//GlobalVariables.potValue *= 2;
//GlobalVariables.userCash -= GlobalVariables.potValue;
//updateGUI();
switch( GlobalVariables.bet )
{
case 5:
WebServiceHandler.doGetWhat( "getgame", "2021", "" );
break;
case 10:
WebServiceHandler.doGetWhat( "getgame", "2022", "" );
break;
case 20:
WebServiceHandler.doGetWhat( "getgame", "2023", "" );
break;
case 40:
WebServiceHandler.doGetWhat( "getgame", "2024", "" );
break;
case 80:
WebServiceHandler.doGetWhat( "getgame", "2025", "" );
break;
case 160:
WebServiceHandler.doGetWhat( "getgame", "2026", "" );
break;
}
//ORIGINAL
//GlobalVariables.gameMode = "BETTING";
//hideDoubleUp();
//
//RETURN VALUE
//GlobalVariables.userCash += GlobalVariables.potValue;
//GlobalVariables.potValue = 0;
//updateGUI();
break;
}