Copy link to clipboard
Copied
Hello, once again I am in need of some help.
I have two classes,
1.) Tile.as class - for a tic tac toe game which creates the acutal tile for the grid
2.) Game.as class - which implements and creates instances of the Tile class puts them on a grid, checks the turn, if there is a solution, and what to do with solution.
I assign questions to each square of the grid much like hollywood squares. If they get the question wrong the opposing teams shape will fill into the grid the user clicked on. My Problem is erratic behavior in setting the right shape into the grid squares. I set a switch case which goes through all the shapes marked, not what I want.
In Tile.as
//Game.isClicked is the e.CurrentTarget found in the game class.
//Game.isClicked.isSet is a string value that checks and makes sure the values are all the same inorder to solve.
public function updateGraphic(e:Event){
switch(Game.isClicked.isSet){
case "X":
tileO.visible = true;
tileX.visible = false;
Game.isClicked.isSet = "O";
Game.isClicked.isSet = "not set";
break;
case "O":
tileO.visible = false;
tileX.visible = true;
Game.isClicked.isSet = "X";
trace("update O after",Game.isClicked.name, Game.isClicked.isSet);
Game.isClicked.isSet = "not set";
break;
}
}
}
In Game.as
//this code is placed on 2 check boxes called "right" or "wrong" obj being called is e.currentTarget.name
public static function checkMark(obj:Object)
{
Tile.activateMouse(questBox,Tile.questionEvent);
switch (obj)
{
case "right" :
TweenMax.to(questBox.feedRight,.5,{autoAlpha:1});
break;
case "wrong" :
isClicked.dispatchEvent(new Event("updateGfx"));
TweenMax.to(questBox.feedWrong,.5,{autoAlpha:1});
break;
}
}
When applied in this manner if two questions have been answered one of which being the wrong answer, both will still go through the Tile.as case statment and reset based on the conditions.
Example: Question 1 shape was Wrong and set to O and Question 2 shape was Wrong and set to X. Once condition is called the O will be set to X in Question 1 Square and the X will be set to O in Question 2 Square.
I hope this explains things a bit, and any help/ideas would be greatly appreciated. Thank you.
Make sure you understand the purpose of the keyword "static".
static
specifies that a variable, constant or method belongs to the class instead of the instances of the class
the erratic behaviour might have to do with the fact that you are accessing the Tile.class instead of the Tile.instances.
Just a guess, because the code you show is not sufficient to isolate the problem.
Copy link to clipboard
Copied
Make sure you understand the purpose of the keyword "static".
static
specifies that a variable, constant or method belongs to the class instead of the instances of the class
the erratic behaviour might have to do with the fact that you are accessing the Tile.class instead of the Tile.instances.
Just a guess, because the code you show is not sufficient to isolate the problem.
Copy link to clipboard
Copied
Thanks for that, now that I think of it I do have these interwoven which might have an effect. I will try to make things a little more direct and seperate, and see if that has any effect.
Copy link to clipboard
Copied
Thanks for helping me walk through that, as a result of your posting I orgainzed things alot better, I had alot of public static vars which ended up being a very confusing mixture. Lesson learned on that end, really appreciate your help!
Copy link to clipboard
Copied
Glad, I could be of service 😉
Find more inspiration, events, and resources on the new Adobe Community
Explore Now