Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Dec 2012
    Location
    Iowa, United States
    Posts
    9

    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 Attached Files

  2. #2
    New Coder djpaul1963's Avatar
    Join Date
    Apr 2012
    Location
    Athens GR
    Posts
    75
    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.

  3. #3
    New to the CF scene
    Join Date
    Dec 2012
    Location
    Iowa, United States
    Posts
    9
    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!

  4. #4
    New Coder djpaul1963's Avatar
    Join Date
    Apr 2012
    Location
    Athens GR
    Posts
    75
    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!

  5. #5
    New to the CF scene
    Join Date
    Dec 2012
    Location
    Iowa, United States
    Posts
    9
    The last thing I needed to do was make it TLF text and read only. Thanks for all the help.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •