Go Back   CodingForums.com > :: Client side development > Flash & ActionScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-04-2013, 05:08 PM   PM User | #1
Nookie
New to the CF scene

 
Join Date: Dec 2012
Location: Iowa, United States
Posts: 9
Thanks: 6
Thanked 0 Times in 0 Posts
Nookie is an unknown quantity at this point
Help with simple tic tac toe Flash game.

New to AS and this has me stumped. Here is my code...

tile1.buttonMode = true;
tile2.buttonMode = true;
tile3.buttonMode = true;
tile4.buttonMode = true;
tile5.buttonMode = true;
tile6.buttonMode = true;
tile7.buttonMode = true;
tile8.buttonMode = true;
tile9.buttonMode = true;

addEventListener(MouseEvent.CLICK, placeX);
function placeX(e:MouseEvent):void
{
e.target.gotoAndStop(2);
trace("You placed an X");
}

addEventListener(MouseEvent.DOUBLE_CLICK, placeO);
function placeO(e:MouseEvent):void
{
e.target.gotoAndStop(3);
trace("You placed an O");
}


The problem is on CLICK it traces out correct and changes the tile to an X like it should. Then when I try to DOUBLE_CLICK I get: "ReferenceError: Error #1069: Property gotoAndStop not found on flash.text.TextField and there is no default value. at ch6_fla::MainTimeline/placeX()" and the tile stays at X.
Like I said I'm pretty new to AS and coding in general so I don't understand what that error means.

I am attaching the file itself so you can see what I have. It's pretty simple but I can't understand why it doesn't work. The file is saved as a .fla 5
Attached Files
File Type: zip tictactoe.zip (7.6 KB, 50 views)
Nookie is offline   Reply With Quote
Old 02-08-2013, 04:17 PM   PM User | #2
djpaul1963
New Coder

 
Join Date: Apr 2012
Location: Athens GR
Posts: 57
Thanks: 0
Thanked 6 Times in 6 Posts
djpaul1963 is an unknown quantity at this point
You must add the mouse listeners to the buttons instead of the stage, like:

tile1.addEventListener(MouseEvent.CLICK, placeX);
tile2.addEventListener(MouseEvent.CLICK, placeX);
...

and
tile1.addEventListener(MouseEvent.DOUBLE_CLICK, placeO);
tile2.addEventListener(MouseEvent.DOUBLE_CLICK, placeO);
...

There is a chance you must swap e.target with e.currentTarget in the handlers as well. I don't have the documentation handy right now.

Another solution is to add MouseChildren = false to the buttons, like: tile1.MouseChildren = false; so only the button itself will trigger the event and not any other children objects (like the text) inside them.

Last edited by djpaul1963; 02-08-2013 at 04:19 PM..
djpaul1963 is offline   Reply With Quote
Users who have thanked djpaul1963 for this post:
Nookie (02-13-2013)
Old 02-11-2013, 04:53 PM   PM User | #3
Nookie
New to the CF scene

 
Join Date: Dec 2012
Location: Iowa, United States
Posts: 9
Thanks: 6
Thanked 0 Times in 0 Posts
Nookie is an unknown quantity at this point
That helped and you were right about needing to change to e.currentTarget, that got rid of the error message, but for some reason it's still not displaying anything on DOUBLE_CLICK. It doesn't go to frame 3 (the O) and when I double click it treats it like a single click and traces out "You placed an X". This doesn't make any sense!
Nookie is offline   Reply With Quote
Old 02-11-2013, 07:33 PM   PM User | #4
djpaul1963
New Coder

 
Join Date: Apr 2012
Location: Athens GR
Posts: 57
Thanks: 0
Thanked 6 Times in 6 Posts
djpaul1963 is an unknown quantity at this point
That's because you must first enable the doubleClick function on the button (yes I know it's ridiculous) like tile1.doubleClickEnabled = true;
On top of that you will realize that doubleClick will fire single click event as well, so you need something like this http://stackoverflow.com/questions/2...s-double-click

Happy coding!
djpaul1963 is offline   Reply With Quote
Users who have thanked djpaul1963 for this post:
Nookie (02-22-2013)
Old 02-22-2013, 04:33 AM   PM User | #5
Nookie
New to the CF scene

 
Join Date: Dec 2012
Location: Iowa, United States
Posts: 9
Thanks: 6
Thanked 0 Times in 0 Posts
Nookie is an unknown quantity at this point
The last thing I needed to do was make it TLF text and read only. Thanks for all the help.
Nookie is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:04 AM.


Advertisement
Log in to turn off these ads.