A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: mix buttons with multiple results

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    3

    mix buttons with multiple results

    im doing a color mixing game.. i have 6 buttons.. with shows the color whn u click on the button..
    how to i mix them??

    btnRed.onPress = function() {
    red._visible = true;

    btnGreen.onPress = function() {
    green._visible = true;

    if (btnGreen.onPress && btnRed.onPress) {
    yellow._visible = true;

    red._visible = false;
    blue._visible = false;
    green._visible = false;
    }

    this coding doesn't work..
    i have no idea.. how the coding should be..
    please HELP me.. =D

  2. #2
    Registered User
    Join Date
    May 2011
    Posts
    3

    multiple buttons.. pls help.. actionscript2.0

    Quote Originally Posted by juannabeh View Post
    im doing a color mixing game.. i have 6 buttons.. which shows the color you want whn u click on the button..
    how to i mix them??

    btnRed.onPress = function() {
    red._visible = true;

    btnGreen.onPress = function() {
    green._visible = true;

    if (btnGreen.onPress && btnRed.onPress) {
    yellow._visible = true;

    red._visible = false;
    blue._visible = false;
    green._visible = false;
    }


    I wana make it like if red n free button is press.. thn the output movieclip will b yellow..this coding doesn't work..
    i have no idea.. how the coding should be..
    please HELP me.. =D

  3. #3
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Hello! Your code contains alot of flaws. I'm not sure how good you are with Actionscript, but I'll try to help you
    And since when was it possible to click 2 buttons at once with only 1 cursor xD?

    Now, from what I understand, you have 2 Buttons, and 3 Movieclips, with the colors Green, Red, and Yellow. You want all of them to be invisible at first. When you click on a button, a movieclip will appear (either green or red, depending on the button you clicked on) with the _visible code. If both of the buttons are active, meaning that both the green and the red movieclips are _visible, the yellow movieclip should appear, right?

    I made 2 Buttons (one for the Green mc, and the other for Red mc). Then I made 3 Movieclips, for the colors green, red and yellow, and I put the Yellow Movieclip above the Green and Red mc's (cause if I don't do that, then the Yellow MC won't be visible -.-*). Then I simply wrote this code on one of the Frame Actions:

    Actionscript Code:
    _root.green._visible = false;
    _root.red._visible = false;
    _root.yellow._visible = false;

    var green_var:Boolean = false;
    var red_var:Boolean = false;

    btnGreen.onPress = function(){
        green_var = !green_var;
        _root.green._visible = !_root.green._visible;
    }

    btnRed.onPress = function(){
        red_var = !red_var;
        _root.red._visible = !_root.red._visible;
    }

    onEnterFrame = function(){
        if(green_var == true && red_var == true){
            _root.yellow._visible = true;
        } else {
            _root.yellow._visible = false;
        }
    }

    Now let's break it down, and explain the code:

    PHP Code:
    _root.green._visible false;
    _root.red._visible false;
    _root.yellow._visible false;
    // this will make the buttons invisible once the movie starts

    var green_var:Boolean false;
    // this is a variable which only contains 2 values,
    //  false or true
    var red_var:Boolean false;
    // same for this one

    btnGreen.onPress = function(){
        
    green_var = !green_var;
        
    // when Green button is clicked, green_var which is false at first,
        //  will turn into the opposite, which would then be true,
        //   because a Boolean only contains either false or true ;)
        // if we know click on this button again, the variable
        //  green_var will turn from true to false. This is just to simplify
        
    _root.green._visible = !_root.green._visible;
        
    // since _visible also only has 2 values, true and false, we can
        //  use ! exclamation mark to turn it into the opposite of what it
        //   is right now. It is from the start, set to false, so when we
        //    click on this button, it will be set to true. It will be visible
    }

    btnRed.onPress = function(){
        
    red_var = !red_var;
        
    // same as above, this time, we have an individual variable for red
        
    _root.red._visible = !_root.red._visible;
    }

    onEnterFrame = function(){
        
    // onEnterFrame will make the codes under loop, so that they
        //  check that the WHOLE time, if those two are true or not
        //   or else they would only have checked at the start of the movie
        
    if(green_var == true && red_var == true){
            
    // if the variables green_var AND red_var are both set to true,
            //  then execute the following codes
            
    _root.yellow._visible true;
            
    // make yellow mc visible
        
    } else {
            
    // if green_var AND red_var are both NOT true at the same time
            //  then execute the following code
            
    _root.yellow._visible false;
            
    // make yellow mc invisible
        
    }

    If you still do not understand, or do not like this code, you can always use another n00bish way xD, here:

    Actionscript Code:
    _root.green._visible = false;
    _root.red._visible = false;
    _root.yellow._visible = false;

    btnGreen.onPress = function(){
        if(_root.green._visible == false){
            // when button is clicked, if green mc is false,
            //  then set it to true
            _root.green._visible = true;
        } else {
            // if not, then make it false. Which means that if
            //  _root.green._visible is not equals to false, but
            //   in this case, it is equals to true, then make it false
            _root.green._visible = false;
        }
    }

    btnRed.onPress = function(){
        // same below as above
        if(_root.red._visible == false){
            _root.red._visible = true;
        } else {
            _root.red._visible = false;
        }
    }

    onEnterFrame = function(){
        if(_root.green._visible == true && _root.red._visible == true){
            // if green is visible AND red is visible at the same time
            _root.yellow._visible = true;
            // make yellow mc visible
        } else {
            // or else
            _root.yellow._visible = false;
            // make yellow mc invisible
        }
    }

    Use the one you find the most suitable for your level

    Hope this Helps. If you need more help, please, go ahead and ask
    Attached Files Attached Files
    I am back, guys ... and finally 18 :P

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

Tags for this Thread

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