• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

IF statement to link 2 buttons

Guest
May 02, 2012 May 02, 2012

Copy link to clipboard

Copied

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,

TOPICS
ActionScript

Views

2.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , May 07, 2012 May 07, 2012

...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 = f

...

Votes

Translate

Translate
LEGEND ,
May 02, 2012 May 02, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 03, 2012 May 03, 2012

Copy link to clipboard

Copied

I don't even know how to start it, I'm a beginner user of Flash and this is my first animation....

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 03, 2012 May 03, 2012

Copy link to clipboard

Copied

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-component.html

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 03, 2012 May 03, 2012

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 04, 2012 May 04, 2012

Copy link to clipboard

Copied

Thanks a lot! I now know how to create and link radio buttons!

The thing is that I'm not using actual radio buttons on my print screen (sorry my post was so confusing) but simple buttons on a  Print screen that shows 2 radio buttons. I've just added 2 simple buttons on the prrint screen, on top of Remote Control and File transfer. 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.

So is it possible to do the same thing with normal buttons? Link simple b1 (Remote Control) + b2 (File transfer) to the main B3 (Connect to partner)? So that:

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

File Transfer button + Connect to Partner = frame +1

Thanks a looot!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 02, 2012 May 02, 2012

Copy link to clipboard

Copied

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)"/>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 03, 2012 May 03, 2012

Copy link to clipboard

Copied

I'm a beginner user of Flash, I don't use Flex. This is my first animation and I don;t understand much coding. I'm not sure I understood your coding, which values do I need to replace with the names of my buttons?

Sorry if this is a stupid reply:)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 04, 2012 May 04, 2012

Copy link to clipboard

Copied

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);

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 05, 2012 May 05, 2012

Copy link to clipboard

Copied

Thank you!

I am gentting error "Access of undefined property or" when I test the movie with this script:

var whichButton:*

filetransfer_btn.addEventListener(MouseEvent.CLICK,reveal);

function reveal(event:MouseEvent):void{

          radio.visible = true;

}

remote_btn.addEventListener(MouseEvent.CLICK, remote);

function remote(event:MouseEvent):void{

          radio.visible = false;

}

whichButton = "filetransfer_btn";  or

whichButton = "remote_btn"

//---

if(whichButton == "filetransfer_btn")

{

      // ctp.gotoAndStop(1);

}

else if(whichButton == "remote_btn")

{

      // ctp.gotoAndStop(158);

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 05, 2012 May 05, 2012

Copy link to clipboard

Copied

Get rid of the "or"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 06, 2012 May 06, 2012

Copy link to clipboard

Copied

Tried removing the OR, it cancels all the coding for linking the 3 buttons.

I'm using CS5.5, AS3. Does the coding above look OK to you? Don't know what to do to make it work...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 06, 2012 May 06, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 07, 2012 May 07, 2012

Copy link to clipboard

Copied

LATEST

...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);

     }


}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines