A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Rock Paper Scissors - Fail. URGENT! I need help!

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    7

    Rock Paper Scissors - Fail. URGENT! I need help!

    I'm trying to do a basic rock paper scissor game for my school project that is due tomorrow since my magic 8 ball didnt work. now this is fighting me. CS5 isnt saying there are any errors but you can't even click on the objects. What am I doing wrong??

    here is my script:

    //This adds the mouse click event to the buttons
    paper.addEventListener(MouseEvent.CLICK, chosen);
    scissor.addEventListener(MouseEvent.CLICK, chosen);
    rock.addEventListener(MouseEvent.CLICK, chosen);

    //Array to hold the names of the paper, sissor and rock.
    var choicesArray:Array = ["paper", "scissor", "rock"];

    function chosen(e:Event):void{
    //This is holds the player choice.
    var playersChoice:String = String(e.target.name);

    //This gets a random value from the choicesArray and .
    var computerChoice:String = choicesArray[Math.floor(Math.random()*choicesArray.length)];

    //player Wins
    if((playersChoice == "paper" && computerChoice == "rock") ||
    (playersChoice == "scissor" && computerChoice == "paper") ||
    (playersChoice == "rock" && computerChoice == "scissor")){
    output_txt.text = "You win! \n The computer chose " + computerChoice;
    }
    //player draw
    else if(playersChoice == computerChoice){
    output_txt.text = "Its a draw \n The computer chose " + computerChoice;
    }
    //player lose
    else{
    output_txt.text = "You lose! \n The computer chose " + computerChoice;
    }
    }

  2. #2
    Member
    Join Date
    Apr 2009
    Posts
    37
    Can you attach a full fla version of your file? If so I would be happy to look at it and see what I could find.

  3. #3
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    Well for starts, the "chosen" function is not an Event as you have it labeled but rather a MouseEvent. And under //player draw, remove the "else" from "else if", should only be "if". That should get it to work, somewhat... might have to work on the first conditional statement (//player wins). Said I lost when I selected paper and the computer had chosen rock. HTH.
    Wile E. Coyote - "Clear as mud?"

  4. #4
    Junior Member
    Join Date
    Mar 2011
    Posts
    7
    thank you!! i think i just attached it... if i did it right lol
    Attached Files Attached Files

  5. #5
    Junior Member
    Join Date
    Mar 2011
    Posts
    7
    Quote Originally Posted by Robb@exo View Post
    Well for starts, the "chosen" function is not an Event as you have it labeled but rather a MouseEvent. And under //player draw, remove the "else" from "else if", should only be "if". That should get it to work, somewhat... might have to work on the first conditional statement (//player wins). Said I lost when I selected paper and the computer had chosen rock. HTH.
    Thank you. I removed the Else but it still doesnt work. I still cant click on my objects nor does any of the font pop up. :/

    Would you be able to save what you just created and upload it onto here? maybe i could compare and see what i did wrong?

  6. #6
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    Just had a look at the file you uploaded. The "chosen" function still associates to an Event which is incorrect, it should be
    PHP Code:
    function chosen(e:MouseEvent):void {
        ...

    And the text color of the textfield is set to white, on a white background, it will just not be seen.
    Wile E. Coyote - "Clear as mud?"

  7. #7
    Junior Member
    Join Date
    Mar 2011
    Posts
    7
    Quote Originally Posted by Robb@exo View Post
    Just had a look at the file you uploaded. The "chosen" function still associates to an Event which is incorrect, it should be
    PHP Code:
    function chosen(e:MouseEvent):void {
        ...

    And the text color of the textfield is set to white, on a white background, it will just not be seen.

    "Wow.. I fail. thank you. So does...
    paper.addEventListener(MouseEvent.CLICK, chosen);
    scissor.addEventListener(MouseEvent.CLICK, chosen);
    rock.addEventListener(MouseEvent.CLICK, chosen);

    turn into

    paper.addEventListener(e:MouseEvent):void {

    i'm really sorry that i'm not completely understanding this. but THANK YOU sooooo much for helping me with this.

  8. #8
    Junior Member
    Join Date
    Mar 2011
    Posts
    7
    Quote Originally Posted by magic8baller View Post
    "Wow.. I fail. thank you. So does...
    paper.addEventListener(MouseEvent.CLICK, chosen);
    scissor.addEventListener(MouseEvent.CLICK, chosen);
    rock.addEventListener(MouseEvent.CLICK, chosen);

    turn into

    paper.addEventListener(e:MouseEvent):void {

    i'm really sorry that i'm not completely understanding this. but THANK YOU sooooo much for helping me with this.

    OMG! IT WORKS!! IF I KNEW WHO YOU WERE ID KISS YOU RIGHT NOW! *dances around the room* thank you thank you thank you!!

  9. #9
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    This code for the buttons is still correct,
    PHP Code:
    paper.addEventListener(MouseEvent.CLICKchosen); 
    There still is the issue however that involves the conditional statement that I had mentioned in an earlier post, but I am glad that at least it's working for you now.
    Last edited by Robb@exo; 03-08-2011 at 01:45 AM.
    Wile E. Coyote - "Clear as mud?"

  10. #10
    Junior Member
    Join Date
    Mar 2011
    Posts
    2

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center