Copy link to clipboard
Copied
After clicking to radio buttons i see next error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at fl.controls::RadioButton/drawFocus()
at fl.core::UIComponent/focusInHandler()
i used next code:
import fl.controls.RadioButtonGroup
public class CoinToss extends MovieClip
{
var radioGroup1:RadioButtonGroup=new RadioButtonGroup("Coin Loss");
//constructor
public function CoinToss()
{
//changing existing cursor to our custom
Mouse.hide();
addEventListener(Event.ENTER_FRAME, myCursor);
my_cursor.mouseEnabled = false;
gameMenu();
}
public function gameMenu():void
{
gotoAndStop('homeScreen');
homeBtn.addEventListener(MouseEvent.CLICK, homeScreen);
playGameBtn.addEventListener(MouseEvent.CLICK, gameScreen);
public function gameScreen(event:MouseEvent):void
{
startGame();
}
public function chooseAnswersGroup():void
{
gameScreen_mc.eagle_rb.group = radioGroup1;
gameScreen_mc.tails_rb.group = radioGroup1;
}
function startGame():void
{
gotoAndStop('gameScreen');
var gameScreen:Tween = new Tween(gameScreen_mc, "x", Elastic.easeOut, -200, 10, 2, true);
chooseAnswersGroup();gameScreen_mc.eagle_rb.selected = true;
so, if i choose eagle_rb or tails_rb radio button from start i see error
i click to button whit existing choosen answer (gameScreen_mc.eagle_rb.selected = true;) then all working ok
can anybody help please?
Hi,
I gone through your code i found it is working fine i think the problem is with the component can you pls remove the component from your lib. and re import in your lib.
Copy link to clipboard
Copied
Hi,
Is you radio buttons are placed directly on stage?
Copy link to clipboard
Copied
yes, i put they to gameScreen_mc movie clip.
Copy link to clipboard
Copied
can u send ur files ??
Copy link to clipboard
Copied
what mean ur?
i can attach files
but can not find way how..
i see just attache image
but how i can attacha zip?
Copy link to clipboard
Copied
can u attach ur full class code ![]()
Copy link to clipboard
Copied
package
{
import flash.display.*;
import flash.events.*;
import flash.display.MovieClip;
import fl.controls.RadioButtonGroup;
import fl.transitions.Tween;
import fl.transitions.easing.*;
//import flash.utils.getDefinitionByName;
import flash.ui.Mouse;
public class CoinToss extends MovieClip
{
var radioGroup1:RadioButtonGroup=new RadioButtonGroup("Coin Loss");
var randomNumber:Number;
var points:Number = 500;
//constructor
public function CoinToss()
{
//changing existing cursor to our custom
Mouse.hide();
addEventListener(Event.ENTER_FRAME, cursorPosition);
my_cursor.mouseEnabled = false;
gameMenu();
}
function cursorPosition(event:Event)
{
my_cursor.x = mouseX;
my_cursor.y = mouseY;
}
//******************************************************************************
//main game menu
public function gameMenu():void
{
gotoAndStop('homeScreen');
homeBtn.addEventListener(MouseEvent.CLICK, homeScreen);
playGameBtn.addEventListener(MouseEvent.CLICK, gameScreen);
howToPlayBtn.addEventListener(MouseEvent.CLICK, howToPlayScreen);
moreGamesBtn.addEventListener(MouseEvent.CLICK, moreGamesScreen);
thanksBtn.addEventListener(MouseEvent.CLICK, thanksScreen);
}
public function homeScreen(event:MouseEvent):void
{
trace("************ We are on HOME Screen ********************");
gotoAndStop('homeScreen');
var homeScreen:Tween = new Tween(homeScreen_mc, "x", Elastic.easeOut, -200, 10, 2, true);
}
public function gameScreen(event:MouseEvent):void
{
startGame();
}
public function howToPlayScreen(event:MouseEvent):void
{
trace("************ We are on HOW TO PLAY Screen ********************");
gotoAndStop('howToPlayScreen');
var howToPlayScreen:Tween = new Tween(howToPlayScreen_mc, "x", Elastic.easeOut, -200, 10, 2, true);
}
public function moreGamesScreen(event:MouseEvent):void
{
trace("************ We are on MORE GAMES Screen ********************");
gotoAndStop('moreGamesScreen');
var moreGamesScreen:Tween = new Tween(moreGamesScreen_mc, "x", Elastic.easeOut, -200, 10, 2, true);
}
public function thanksScreen(event:MouseEvent):void
{
trace("************ We are on THANKS Screen ********************");
gotoAndStop('thanksScreen');
var thanksScreen:Tween = new Tween(thanksScreen_mc, "x", Elastic.easeOut, -200, 10, 2, true);
}
//******************************************************************************
public function chooseAnswersGroup():void
{
gameScreen_mc.eagle_rb.group = radioGroup1;
gameScreen_mc.tails_rb.group = radioGroup1;
}
function startGame():void
{
trace("************ We are on GAME Screen ********************");
gotoAndStop('gameScreen');
var gameScreen:Tween = new Tween(gameScreen_mc, "x", Elastic.easeOut, -200, 10, 2, true);
trace(">> game starting...");
chooseAnswersGroup();
gameScreen_mc.eagle_rb.selected = true;
gameScreen_mc.eagle_rb.visible=true;
gameScreen_mc.tails_rb.visible=true;
gameScreen_mc.coin_mc.visible = false;
gameScreen_mc.coin_first.visible = true;
gameScreen_mc.points_txt.text="500";
gameScreen_mc.eagle_rb.label="Eagle";
gameScreen_mc.tails_rb.label="Tails";
gameScreen_mc.eagle_error_txt.text = "";
gameScreen_mc.tails_error_txt.text = "";
gameScreen_mc.coinToss_btn.addEventListener(MouseEvent.CLICK, checkAnswer);
points = 500;
/*gameScreen_mc.earn100.visible = false;
gameScreen_mc.earn200.visible = false;
gameScreen_mc.earn300.visible = false;
gameScreen_mc.earn400.visible = false;
gameScreen_mc.earn500.visible = true;
gameScreen_mc.earn600.visible = false;
gameScreen_mc.earn700.visible = false;
gameScreen_mc.earn800.visible = false;
gameScreen_mc.earn900.visible = false;
gameScreen_mc.earn1000.visible = false;*/
}
function checkAnswer(event:MouseEvent):void
{
gameScreen_mc.coin_mc.visible = true;
gameScreen_mc.coin_first.visible = false;
randomNumber=Math.random();//generate random number
trace("Random number: " + randomNumber);
if (randomNumber < 0.5)
{
gameScreen_mc.coin_mc.gotoAndPlay("eagle");
}
else
{
gameScreen_mc.coin_mc.gotoAndPlay("tails");
}
if (radioGroup1.selection.label == "Eagle" && randomNumber < 0.5)
{
gameScreen_mc.eagle_error_txt.text = "correct";//if user guessed then show 'correct' message, else 'wrong' message
gameScreen_mc.tails_error_txt.text = "";//from start this text fild is empty
points+=100;//added or deleted 100 points, depends of user guessed or not
gameScreen_mc.points_txt.text = String(points);//changing type(from number to string) and showing user points
gameScreen_mc.add100_mc.gotoAndPlay("add100");//animation for 'added +100 points' or 'deleted -100 points'
trace("Eagle - correct");
trace("Player points: " + points);
trace("+++++++++++++++++++++++++++++++++++++++++++++++++");
}
else if (radioGroup1.selection.label == "Eagle" && randomNumber > 0.5)
{
gameScreen_mc.eagle_error_txt.text = "wrong";
gameScreen_mc.tails_error_txt.text = "";
points-=100;
gameScreen_mc.points_txt.text = String(points);
gameScreen_mc.del100_mc.gotoAndPlay("del100");
trace("Eagle - wrong");
trace("Player points: " + points);
trace("+++++++++++++++++++++++++++++++++++++++++++++++++");
}
else if (radioGroup1.selection.label == "Tails" && randomNumber > 0.5)
{
gameScreen_mc.tails_error_txt.text = "correct";
gameScreen_mc.eagle_error_txt.text = "";
points+=100;
gameScreen_mc.points_txt.text=String(points);
gameScreen_mc.coin_mc.gotoAndStop("tails");
gameScreen_mc.add100_mc.gotoAndPlay("add100");
trace("Tails - correct");
trace("Player points: " + points);
trace("+++++++++++++++++++++++++++++++++++++++++++++++++");
}
else
{
gameScreen_mc.tails_error_txt.text = "wrong";
gameScreen_mc.eagle_error_txt.text = "";
points-=100;
gameScreen_mc.points_txt.text = String(points);
gameScreen_mc.del100_mc.gotoAndPlay("del100");
trace("Tails - wrong");
trace("Player points: " + points);
trace("+++++++++++++++++++++++++++++++++++++++++++++++++");
}
/*if (points == 100)
{
gameScreen_mc.earn100.visible = true;
gameScreen_mc.earn200.visible = false;
gameScreen_mc.earn300.visible = false;
gameScreen_mc.earn400.visible = false;
gameScreen_mc.earn500.visible = false;
gameScreen_mc.earn600.visible = false;
gameScreen_mc.earn700.visible = false;
gameScreen_mc.earn800.visible = false;
gameScreen_mc.earn900.visible = false;
gameScreen_mc.earn1000.visible = false;
}
if (points == 200)
{
gameScreen_mc.earn100.visible = false;
gameScreen_mc.earn200.visible = true;
gameScreen_mc.earn300.visible = false;
gameScreen_mc.earn400.visible = false;
gameScreen_mc.earn500.visible = false;
gameScreen_mc.earn600.visible = false;
gameScreen_mc.earn700.visible = false;
gameScreen_mc.earn800.visible = false;
gameScreen_mc.earn900.visible = false;
gameScreen_mc.earn1000.visible = false;
}
if (points == 300)
{
gameScreen_mc.earn100.visible = false;
gameScreen_mc.earn200.visible = false;
gameScreen_mc.earn300.visible = true;
gameScreen_mc.earn400.visible = false;
gameScreen_mc.earn500.visible = false;
gameScreen_mc.earn600.visible = false;
gameScreen_mc.earn700.visible = false;
gameScreen_mc.earn800.visible = false;
gameScreen_mc.earn900.visible = false;
gameScreen_mc.earn1000.visible = false;
}
if (points == 400)
{
gameScreen_mc.earn100.visible = false;
gameScreen_mc.earn200.visible = false;
gameScreen_mc.earn300.visible = false;
gameScreen_mc.earn400.visible = true;
gameScreen_mc.earn500.visible = false;
gameScreen_mc.earn600.visible = false;
gameScreen_mc.earn700.visible = false;
gameScreen_mc.earn800.visible = false;
gameScreen_mc.earn900.visible = false;
gameScreen_mc.earn1000.visible = false;
}
if (points == 500)
{
gameScreen_mc.earn100.visible = false;
gameScreen_mc.earn200.visible = false;
gameScreen_mc.earn300.visible = false;
gameScreen_mc.earn400.visible = false;
gameScreen_mc.earn500.visible = true;
gameScreen_mc.earn600.visible = false;
gameScreen_mc.earn700.visible = false;
gameScreen_mc.earn800.visible = false;
gameScreen_mc.earn900.visible = false;
gameScreen_mc.earn1000.visible = false;
}
if (points == 600)
{
gameScreen_mc.earn100.visible = false;
gameScreen_mc.earn200.visible = false;
gameScreen_mc.earn300.visible = false;
gameScreen_mc.earn400.visible = false;
gameScreen_mc.earn500.visible = false;
gameScreen_mc.earn600.visible = true;
gameScreen_mc.earn700.visible = false;
gameScreen_mc.earn800.visible = false;
gameScreen_mc.earn900.visible = false;
gameScreen_mc.earn1000.visible = false;
}
if (points == 700)
{
gameScreen_mc.earn100.visible = false;
gameScreen_mc.earn200.visible = false;
gameScreen_mc.earn300.visible = false;
gameScreen_mc.earn400.visible = false;
gameScreen_mc.earn500.visible = false;
gameScreen_mc.earn600.visible = false;
gameScreen_mc.earn700.visible = true;
gameScreen_mc.earn800.visible = false;
gameScreen_mc.earn900.visible = false;
gameScreen_mc.earn1000.visible = false;
}
if (points == 800)
{
gameScreen_mc.earn100.visible = false;
gameScreen_mc.earn200.visible = false;
gameScreen_mc.earn300.visible = false;
gameScreen_mc.earn400.visible = false;
gameScreen_mc.earn500.visible = false;
gameScreen_mc.earn600.visible = false;
gameScreen_mc.earn700.visible = false;
gameScreen_mc.earn800.visible = true;
gameScreen_mc.earn900.visible = false;
gameScreen_mc.earn1000.visible = false;
}
if (points == 900)
{
gameScreen_mc.earn100.visible = false;
gameScreen_mc.earn200.visible = false;
gameScreen_mc.earn300.visible = false;
gameScreen_mc.earn400.visible = false;
gameScreen_mc.earn500.visible = false;
gameScreen_mc.earn600.visible = false;
gameScreen_mc.earn700.visible = false;
gameScreen_mc.earn800.visible = false;
gameScreen_mc.earn900.visible = true;
gameScreen_mc.earn1000.visible = false;
}
if (points == 1000)
{
gameScreen_mc.earn100.visible = false;
gameScreen_mc.earn200.visible = false;
gameScreen_mc.earn300.visible = false;
gameScreen_mc.earn400.visible = false;
gameScreen_mc.earn500.visible = false;
gameScreen_mc.earn600.visible = false;
gameScreen_mc.earn700.visible = false;
gameScreen_mc.earn800.visible = false;
gameScreen_mc.earn900.visible = false;
gameScreen_mc.earn1000.visible = true;
}*/
if (points == 1000 || points == 0)
{
gameResult();
}
}
function gameResult():void
{
if (points == 1000)
{
gotoAndStop('finalScreen');
finalScreen_mc.message_txt.text = "You win 1000 points!";
trace("RESULT: win 1000");
}
else if (points == 0)
{
gotoAndStop('finalScreen');
finalScreen_mc.message_txt.text = "You are lost your points!";
trace("RESULT: lost");
}
finalScreen_mc.playAgain_btn.addEventListener(MouseEvent.CLICK, playAgain);
finalScreen_mc.homeBtn.addEventListener(MouseEvent.CLICK, goToHomeScreen);
}
function playAgain(event:MouseEvent):void
{
startGame();
}
function goToHomeScreen(event:MouseEvent):void
{
gameMenu();
}
}
}
Copy link to clipboard
Copied
Hi,
I gone through your code i found it is working fine i think the problem is with the component can you pls remove the component from your lib. and re import in your lib.
Copy link to clipboard
Copied
yes, its help, and now i dont see error in output window
but when i click to other radiobutton i see strange blue border:) what is it?
attached picture.
Copy link to clipboard
Copied
It's a tab focus rect you can remove it by
stage.stageFocusRect= false
Copy link to clipboard
Copied
ok
i can not understand 2 things
1. why after delete and paste radiobutton in my library i dont see error
2. why if i click to 'eagle' rabiobutton i dont see this border? also i don't see this border in future if i click to 'tails'
Copy link to clipboard
Copied
Here you go:-
1) It is possible that you have change/delete any component related file in library. So when u replace it you got it right.
2) It's a tab focus rect of flash player. Possible you have pressed tab that's why u can see it on radio button.
Copy link to clipboard
Copied
ok
thank you
Copy link to clipboard
Copied
welcome
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more