Skip navigation
etvaaa
Currently Being Moderated

IF statement to link 2 buttons

May 2, 2012 5:00 PM

Tags: #design #button #buttons #if #then #statement #button-interactions

I've got 2 radio buttons on a print screen and a button:

Untitled.png

 

I want the "Connct to partnet" button to lead to different frames, depending on which radio button is clicked on the print screen.

 

So If "Remote control" is clicked, then the "connect to partner" gotoandStop at frame x

     If "File transfer" is clicked, then the "connect to partner" will gotoandStop at frame x+1

 

 

I would really appreciate any help!

 

Thanks a lot in advance,

 
Replies
  • Currently Being Moderated
    May 2, 2012 5:57 PM   in reply to etvaaa

    Do you have any code to show for an attempt that hasn't worked for you?

     
    |
    Mark as:
  • Currently Being Moderated
    May 2, 2012 8:07 PM   in reply to etvaaa

    if you using Flex, like this

     

    private function clickHandler(event:MouseEvent):void

    {

        var val:Object = radiogroup.selectedValue;

        if(val == "foo")

        {

            // myMC.gotoAndStop(x);

        }

        else if(val == "bar")

        {

            // myMC.gotoAndStop(x + 1);

        }

    }

    ...

     

    <fx:Declarations>

        <s:RadioButtonGroup id="radiogroup"/>

    </fx:Declarations>

    <s:VGroup x="82" y="119">

        <s:RadioButton label="Remote control" value="foo" groupName="radiogroup"/>

        <s:RadioButton label="File transfer" value="bar" groupName="radiogroup"/>

    </s:VGroup>

    <s:Button x="82" y="179" label="Connect to Partner" click="clickHandler(event)"/>

     
    |
    Mark as:
  • Currently Being Moderated
    May 3, 2012 12:29 PM   in reply to etvaaa

    If you have no experience coding with Actionscript at all, your best bet will be to search Google for tutorials about RadioButtons and Buttons.  Try using search terms like "AS3 RadioButton tutorial" and similarly for a Button.  You might get lucky and find one that does pretty much what you are trying to do.  Here's a link to one of the first results found using that search... it appears to have similarities to what you are doing if you look thru all three parts of it.

     

    http://kirill-poletaev.blogspot.com/2010/09/using-radiobutton-componen t.html

     
    |
    Mark as:
  • Currently Being Moderated
    May 3, 2012 10:34 PM   in reply to etvaaa
     
    |
    Mark as:
  • Currently Being Moderated
    May 4, 2012 3:30 PM   in reply to etvaaa

    one of the ways you can do this is by creating an extra variable such as:

     

    var whichButton:*

     

    //---

     

    and then when you set the visible = true by clicking one of the "simple buttons", set a value for whichButton:

     

    whichButton = "remoteControl"

     

    or

     

    whichButton = "fileTransfer"

     

    //---

     

    and then when you click "connect to partner", you can use the if/else as shown above:

     

    if(whichButton == "remoteControl")

    {

          // ctp.gotoAndStop(framex);

    }

    else if(whichButton == "fileTransfer")

    {

          // ctp.gotoAndStop(framex + 1);

    }

     
    |
    Mark as:
  • Currently Being Moderated
    May 5, 2012 5:40 PM   in reply to etvaaa

    Get rid of the "or"

     
    |
    Mark as:
  • Currently Being Moderated
    May 6, 2012 9:12 AM   in reply to etvaaa

    No, the coding does not look okay... remove the "or"   if you can't find it, use the search feature (the magnifying glass in the top toolbar)

     

    Also, I won't say that the code is okay or will work at all for what you are after.  That would be up to whoever gave it to you to work out with you.  I generally avoid intruding on other people's efforts to help.  So when someone else decides they want to do so, it's up to them to follow thru and support what they offer.  Try emailing whoever gave you the code to get their help if they are not following up on it.

     
    |
    Mark as:
  • Currently Being Moderated
    May 7, 2012 1:50 PM   in reply to Ned Murphy

    ...please understand that i dont know how you toggle the radio buttons... i only saw you say: "I have a visible = true and false coding when clicking on the buttons, so it looks as if a radio button is selected when I click on the simple button."

     

    ...also, since you didnt show the function for clicking the connect button, i made one up so you can see the logic that i intended

     

    //---

     

    Remote Control button clicked + Connect to Partner button cliked = frame x

    File Transfer button + Connect to Partner = frame +1

     

    //---

     

    //sets a default value, in case neither radio button gets clicked

     

    var whichButton:* = "filetransfer_btn";


     

    filetransfer_btn.addEventListener(MouseEvent.CLICK,reveal);

    function reveal(event:MouseEvent):void{

              radio1.visible = true;

              radio2.visible = false;

              whichButton = "filetransfer_btn";

    }


     

    remote_btn.addEventListener(MouseEvent.CLICK, remote);

    function remote(event:MouseEvent):void{

              radio2.visible = true;

              radio1.visible = false;

              whichButton = "remote_btn"

    }


     

    connectToPartner.addEventListener(MouseEvent.CLICK, connect);

    function connect(event:MouseEvent):void{

             

         if(whichButton == "filetransfer_btn")

         {

               gotoAndStop(framex);

         }

         else if(whichButton == "remote_btn")

         {

               gotoAndStop(framex +1);

         }


     

    }

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points