A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Two questions

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    5

    Question Two questions

    I have a movieclip named physicalMenu and inside of it on frame 2 is a button named attack1Btn.

    I am using the code

    Actionscript Code:
    physicalMenu.attack1Btn.onRelease = function() {
        if (players_turn == true && player_attack == false && player_magic == false) {
            player_attack = true;
            player.gotoAndPlay('attack1');
        }
    }

    to specify what I want the button to do. The problem is that its not working.

    I think its because the actionscript is looking for the button on frame 1 of the physicalMenu movieclip. (If the button is on frame 1 the code works fine.)

    So my 2 questions are
    1. Why isnt the code working?
    2. How can I make it work without adding actionscript to the individual button?

  2. #2
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Where are the variables, players_turn, player_attach and player_magic located? Inside the physicalMenu movieclip, or outside of it?
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    5
    Outside

  4. #4
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Oh, I see why it's only working on frame 1. It's because you set the actionscript for the code for the button on Frame 1 of that movieclip, and they ain't refreshed when the button is on another frame. Use this code:

    Actionscript Code:
    onEnterFrame = function(){
        physicalMenu.attack1Btn.onRelease = function() {
            if (players_turn == true && player_attack == false && player_magic == false) {
                player_attack = true;
                player.gotoAndPlay('attack1');
            }
        }
    }
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  5. #5
    Junior Member
    Join Date
    Oct 2011
    Posts
    5
    Thanks so much! This worked perfectly!

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